我以异步导入lodash为例,但它却包含在主块中
Version: webpack 4.23.1
module.exports = {
mode: "development",
context: __dirname,
devtool: 'sourcemap',
entry: {
"entry1": "./src/entry1.ts"
},
output: {
path: __dirname + "/dist",
filename: "[name].js",
chunkFilename: "[name].js",
},
// ...
}
我编写了一个简单的代码来重现问题
document.addEventListener('DOMContentLoaded', async () => {
console.log('DOMContentLoaded')
// lodash should be made into a separate chunk
// but it gets included in the entry1 chunk
const _ = await import('lodash')
console.log('loaded test chunk')
console.log(_.concat)
})
完整的回购链接在下面
https://github.com/unlocomqx/webpack4-async-chunk
答案 0 :(得分:0)
我发现了我的错误
我在tsconfig中更改了"module": "esnext",
并成功了!