带有异步块的Webpack CommonsChunkPlugin

时间:2017-05-04 14:38:57

标签: webpack

我试图删除我的webpack chinks中的模块重复使用本文: https://medium.com/webpack/webpack-bits-getting-the-most-out-of-the-commonschunkplugin-ab389e5f318

我写这段代码:

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 )
                ),
            }
        ),
    ],
    // …

它产生了这组块:

webpack stats

正如你所看到的,我的preact-and-stuff软件包有两个副本(chunk-34d7bcc8f252514ef939和chunk-a1ef228b5aacb773dff7)。它用在chunk-8559295ee847c621304a和chunk-ac0def536d8c04b6d692中(没有CommonsChunkPlugin,每个块中都有一个模块的副本)。使用import()函数异步加载所有块。

我评论了count > 1,因为它被视为一次使用,但在输出日志中被计算两次(我不知道为什么)。

为什么有两份必需的单独块以及如何修复它?

谢谢!

0 个答案:

没有答案