简体   繁体   English

Webpack的CommonChunksPlugin配置与延迟加载的模块?

[英]Webpack's CommonChunksPlugin configuration with lazy loaded modules?

I'm using Webpack with CommonChunksPlugin . 我正在将Webpack与CommonChunksPlugin一起使用。

My problem is with lazy loaded modules. 我的问题是延迟加载的模块。
When I load lazy modules ( 0.js and 1.js in image) , Where each uses the Http Module , it seems that Http is embedded/repeated in EACH module : 当我加载惰性模块(图像中的0.js1.js )时,每个Http Module都使用Http Module ,似乎Http嵌入/重复出现在EACH模块中:

The entries in my file are : 我文件中的条目是:

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

With CommonsChunkPlugin configured as : 将CommonsChunkPlugin配置为:

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

— I get this result where you can see multiple http.js both in bundle & 1.js& 0.js. —我得到了这个结果 ,您可以在bundle&1.js&0.js中看到多个http.js。

在此处输入图片说明

With CommonsChunkPlugin configured with async ( as written in here ) : 使用配置了async CommonsChunkPlugin (如此处所示 ):

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

— I get this result where you can see tha 0.js and 1.js are OK but the bundle.js now contains dups as vendor(?!?!) —我得到了这个结果 ,您可以看到tha 0.js1.js都可以,但是bundle.js现在包含dups作为vendor(?!?!)

在此处输入图片说明

Question: 题:

I've read the docs But as you can see , I'm trying to do something without success. 我已经阅读了文档,但是正如您所看到的,我正在尝试做一些没有成功的事情。

How can I fix the config so that common chunks will be extracted and not be repeated ? 如何修复配置,以便提取公共块而不重复这些块?

webpack.config webpack.config

Was having the same issue as you are/were facing. 与您/正面临相同的问题。 In my case, I've removed the name parameter from the configuration and set async to true and children to true as well. 就我而言,我已从配置中删除了name参数,并将async设置为true并将children设置为true。 Also, make sure that the CommonChunksPlugin is the last plugin in the array of plugins. 另外,请确保CommonChunksPlugin是插件数组中的最后一个插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM