繁体   English   中英

使用System.import进行Webpack 2代码拆分:依赖关系的依赖关系

[英]Webpack 2 code splitting with System.import: Dependencies of dependencies

好的,所以我正在努力在一堆异步加载的块中正确地拆分我们的JS。

我在几个入口点使用import ,这很有用:

module.exports = Promise.all([
    import('moment'),
    import('some-other-module')
]).then((deps) => {
    let [moment, someOtherModule] = deps;
}

其他地方:

module.exports = Promise.all([
    import('moment'),
]).then((deps) => {
    let [moment] = deps;
}

的WebPack成功创建单独的块momentsome-other-module并在需要时加载文件异步。

然而:

some-other-module实际上需要moment为好,使的WebPack包括moment还在some-other-module的块,导致重复。

这是预期的行为吗? 如果是这样,推荐的解决方案是什么?

我在webpack.config的插件部分添加了以下代码行,它将依赖关系分开并根据需要并行加载

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

你可以在这个页面看到CommonsChunkPlugin async的描述https://webpack.js.org/plugins/commons-chunk-plugin/

暂无
暂无

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

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