webpack/examples/move-to-parent/webpack.config.js

63 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-12-22 19:33:40 +08:00
var path = require("path");
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
var outputOptions = {
path: path.join(__dirname, "js"),
filename: "[name].bundle.js",
chunkFilename: "[id].chunk.js"
};
module.exports = [{
name: "page",
2017-11-21 18:04:18 +08:00
mode: "production",
2014-12-22 19:33:40 +08:00
entry: {
page: "./page"
2014-12-22 19:33:40 +08:00
},
output: outputOptions
}, {
name: "pageA",
2017-11-21 18:04:18 +08:00
mode: "production",
entry: {
pageA: "./page"
2014-12-22 19:33:40 +08:00
},
output: outputOptions,
2014-12-22 19:33:40 +08:00
plugins: [
//check for common modules in children of pageA and move them to the parent
2015-10-31 23:31:10 +08:00
new CommonsChunkPlugin({
name: "pageA",
children: true
}),
]
}, {
name: "pageB",
2017-11-21 18:04:18 +08:00
mode: "production",
entry: {
pageB: "./page"
},
output: outputOptions,
plugins: [
2014-12-22 19:33:40 +08:00
// the same for pageB but move them if at least 3 children share the module
2015-10-31 23:31:10 +08:00
new CommonsChunkPlugin({
name: "pageB",
children: true,
minChunks: 3
}),
]
}, {
name: "pageC",
2017-11-21 18:04:18 +08:00
mode: "production",
entry: {
pageC: "./page"
},
output: outputOptions,
plugins: [
2014-12-22 19:33:40 +08:00
// the same for pageC and pageD but with a custom logic for moving
2015-10-31 23:31:10 +08:00
new CommonsChunkPlugin({
name: "pageC",
2015-10-31 23:31:10 +08:00
children: true,
minChunks: function(module, count) {
// move only module "b"
return !/b\.js/.test(module.identifier());
2015-10-31 23:31:10 +08:00
}
2014-12-22 19:33:40 +08:00
})
]
}];