带有异步块的Webpack CommonChunkPlugin
我尝试使用本文删除我的网页中的模块重复漏洞: 我写这段代码:带有异步块的Webpack CommonChunkPlugin,webpack,Webpack,我尝试使用本文删除我的网页中的模块重复漏洞: 我写这段代码: const config = { entry: { main: './app/index.ts', }, plugins: [ new Webpack.optimize.CommonsChunkPlugin( { children: true, async: true,
const config = {
entry: {
main: './app/index.ts',
},
plugins: [
new Webpack.optimize.CommonsChunkPlugin(
{
children: true,
async: true,
minChunks: ( module, count ) => (
// ( count > 1 )
module.resource
&& /\/node_modules\/(?:preact|immutability-helper|small-redux|preact-small-redux)\//.test( module.resource )
),
}
),
],
// …
它可以生成这组块:
如您所见,有两份我的preact和stuff包(chunk-34D7BC8F252514EF939和chunk-a1ef228b5aacb773dff7)。它用于chunk-8559295ee847c621304a和chunk-ac0def536d8c04b6d692(如果没有CommonChunkPlugin,每个块中都有该模块的副本)。使用import()
函数异步加载所有块
我注释掉了count>1
,因为它被计算为一次使用,但在输出日志中被计算了两次(我不知道为什么)
为什么需要两个独立块的副本,以及如何修复它
谢谢 探索性尝试:如果您将
minChunks
设置为2,您是否仍然有2个重复的异步块?如果我将minChunks设置为2,则在chunk-8559295ee847c621304a和chunk-ac0def536d8c04b6d692中有该模块的副本(因为根本没有CommonChunkPlugin)。当我在minChunks
函数中添加console.log
和module.resource
和count
时,有两行代码,其中需要的模块计数为“1”。探索性尝试:如果将minChunks
设置为2,您是否仍有2个重复的异步块?如果我将minChunks设置为2,则chunk-8559295ee847c621304a和chunk-ac0def536d8c04b6d692中有该模块的副本(因为根本没有CommonChunkPlugin)。当我在minChunks
函数中添加console.log
和module.resource
和count
时,有两行代码包含计数为“1”的必需模块。