[英]Webpack 2 + React - nested routes when code splitting with System.import
[英]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成功创建单独的块moment
和some-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.