I'm just getting started with Webpack and have hit a snag.
I store my modules in assets/js/someModule.js
. For example, here's a loadSnaps
module I'm working on (AMD).
define('loadSnaps', ['jquery'], function($) {
// Load latest snaps into DOM
});
In my webpack.config.js
I create an alias to this module:
...
resolve: {
alias: {
loadSnaps: 'assets/js/loadSnaps.js'
}
}
...
I'd like to know, is there an easier way of doing this without having to create an alias each time? Is it possible to specify the path of my modules so that I can just require
them via there name?
Figured it out using resolve.root
:
var path = require('path');
module.exports = {
entry: './entry.js',
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
},
resolve: {
root: [
path.resolve('./assets/js')
]
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.