I want to create several entry points for a website, which is pretty easy to do in Webpack using an object for a property entry, like here .
But as the site grows (and it will inevitably be) adding each entry point seems cumbersome and error prone. Therefore, I would just point to the directory and say "these are all entry points."
So, I prepared this:
var path = require('path');
var fs = require('fs');
var entryDir = path.resolve(__dirname, '../source/js');
var entries = fs.readdirSync(entryDir);
var entryMap = {};
entries.forEach(function(entry){
var stat = fs.statSync(entryDir + '/' + entry);
if (stat && !stat.isDirectory()) {
var name = entry.substr(0, entry.length -1);
entryMap[name] = entryDir + '/' + entry;
}
});
module.exports = {
entry: entryMap,
output: {
path: path.resolve(__dirname, '../static/js'),
filename: "[name]"
},
...
This works fine, but is there an option or configuration in Webpack that will handle this for me?
source
share