我正在尝试以异步导入 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)
})
完整的 repo 链接如下
https://github.com/unlocomqx/webpack4-async-chunk
我发现了我的错误
我"module": "esnext",
在 tsconfig 中进行了更改并且它起作用了!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句