1. var path = require("path");
    2. var { AggressiveMergingPlugin } = require("../../").optimize;
    3. module.exports = {
    4. // mode: "development" || "production",
    5. entry: {
    6. pageA: "./pageA",
    7. pageB: "./pageB",
    8. pageC: "./pageC"
    9. },
    10. output: {
    11. path: path.join(__dirname, "dist"),
    12. filename: "[name].bundle.js",
    13. chunkFilename: "[id].chunk.js"
    14. },
    15. plugins: [
    16. new AggressiveMergingPlugin({
    17. minSizeReduce: 1.5
    18. })
    19. ],
    20. devtool: false,
    21. optimization: {
    22. chunkIds: "deterministic" // To keep filename consistent between different modes (for example building only)
    23. }
    24. };

    此插件会尽可能的合并共用chunk, 例如
    aggressive-merging - 图1
    页面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
    可以看出没有共用的模块没有进行合并。