var path = require("path");
var { AggressiveMergingPlugin } = require("../../").optimize;
module.exports = {
// mode: "development" || "production",
entry: {
pageA: "./pageA",
pageB: "./pageB",
pageC: "./pageC"
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].bundle.js",
chunkFilename: "[id].chunk.js"
},
plugins: [
new AggressiveMergingPlugin({
minSizeReduce: 1.5
})
],
devtool: false,
optimization: {
chunkIds: "deterministic" // To keep filename consistent between different modes (for example building only)
}
};
此插件会尽可能的合并共用chunk, 例如
页面entry为[‘pageA.js’, ‘pageB.js’, ‘pageC.js’]
pageA.js 依赖a.js和common.js
pageB.js 依赖b.js和common.js
pageC.js 依赖a.js和b.js
使用AggressiveMergingPlugin后,打包结果为
a_js-b_js.chunk.js
a_js-b_js-common_js.chunk.js
pageA.bundle.js
pageB.bundle.js
pageC.bundle.js
不使用时为
a_js-b_js.chunk.js
a_js-common_js.chunk.js
b_js-common_js.chunk.js
pageA.bundle.js
pageB.bundle.js
pageC.bundle.js
可以看出没有共用的模块没有进行合并。