Webpack的CommonChunksPlugin配置是否有延迟加载的模块?

时间:2018-01-05 16:49:50

标签: javascript webpack nativescript

我在CommonChunksPlugin使用Webpack。

我的问题是延迟加载的模块 当我在图片中加载延迟模块(0.js1.js)时,每个模块都使用Http Module,似乎Http在每个模块中嵌入/重复:

我文件中的条目是:

 entry: {
            bundle: aot ? "./main.aot.ts" : "./main.ts",
            vendor: "./vendor",
        },

将CommonsChunkPlugin配置为:

 new webpack.optimize.CommonsChunkPlugin({
            name: ["vendor"],
        }),

- 我得到this result,您可以在其中看到多个http.js在捆绑和放大器中1.js&安培; 0.js。

enter image description here

CommonsChunkPlugin配置为async (如here所示):

 new webpack.optimize.CommonsChunkPlugin({
           async: true, 
           children: true, 

        }),

- 我得到this result您可以看到0.js1.js正常但bundle.js现在包含重复的供应商(?!?!)

enter image description here

问题:

我已经阅读了docs但是你可以看到,我试图做一些没有成功的事情。

如何修复配置以便提取常见的块而不重复?

webpack.config

1 个答案:

答案 0 :(得分:0)

遇到与您/面临的问题相同的问题。 就我而言,我已从配置中删除了name参数,并将async设置为true,将child设置为true。 另外,请确保CommonChunksPlugin是插件数组中的最后一个插件。

相关问题