首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CommonsChunkPlugin react区块文件过大

CommonsChunkPlugin react区块文件过大
EN

Stack Overflow用户
提问于 2017-10-25 10:17:22
回答 1查看 499关注 0票数 0

我有一个用webpack2构建的react项目,但是构建的块文件都超过了大小,总大小超过10M!以下是我的配置和日志输出的一部分。

代码语言:javascript
复制
module.exports = {
    entry: {
        app: appConf.entry
    },
    output: {
        path: appConf.buildRoot,
        publicPath: appConf.assetsPublicPath,
        filename: assetsPath('js/[name].[chunkhash].js'),
        chunkFilename: assetsPath('js/[id].[chunkhash].js')
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor',
            minChunks: function(module, count) {
                // any required modules inside node_modules are extracted to vendor
                return (module.resource && /\.js$/.test(module.resource) && module.resource.indexOf(path.join(__dirname, '../../node_modules')) === 0);
            }
        }),
        // extract webpack runtime and module manifest to its own file in order to
        // prevent vendor hash from being updated whenever app bundle is updated
        new webpack.optimize.CommonsChunkPlugin({
            name: 'manifest',
            chunks: ['vendor']
        })
    ]
};

some of my component chunk size are almost 1M!!!

EN

回答 1

Stack Overflow用户

发布于 2017-10-25 10:24:16

一个原因可能是一些lib在所有生成的块上重复,以避免您可以使用:

代码语言:javascript
复制
new webpack.optimize.CommonsChunkPlugin({
  children: true,
  minChunks: 2
})

这样,您就是在告诉webpack创建另一个具有重复lib的块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46922879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档