I need to webpack all the js file in the script folder.I tried this
module.exports = {
module: {
loaders: [
{
test: /\\.js$/,
ex
Just using glob.sync will result in sequential filenames, such as 0.[hash].js and 1.[hash].js, because entry expects an object with the the name of the file in the key and its location in the value, but glob.sync returns an array.
The following method has the benefit of producing an object with keys and values based on the filenames, you can also add additional entries, such as vendor and common. Requires lodash.
const glob = require("glob");
const _ = require('lodash');
module.exports = {
entry: Object.assign({},
_.reduce(glob.sync("./src/*.js"),
(obj, val) => {
const filenameRegex = /([\w\d_-]*)\.?[^\\\/]*$/i;
obj[val.match(filenameRegex)[1]] = val;
return obj;
},
{}),
{
vendor: [
'lodash'
]
}
),
output: {
filename: '[name].[chunkhash].bundle.js',
path: path.resolve(__dirname, 'dist')
}
}
The latter will produce the following object and pass it to entry, provided we have index.js and app.js in the ./src directory:
{
index: './src/index.js',
app: './src/app.js',
vendor: [ 'lodash' ]
}