好的,所以我正在努力将我们的 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
,使 Webpackmoment
也包含在some-other-module
's 块中,导致重复。
这是预期的行为吗?如果是这样,推荐的解决方案是什么?