Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有异步块的Webpack CommonChunkPlugin_Webpack - Fatal编程技术网

带有异步块的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”的必需模块。