0

我正在尝试以异步导入 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

4

1 回答 1

0

我发现了我的错误

"module": "esnext",在 tsconfig 中进行了更改,它起作用了!

于 2018-11-01T20:38:33.813 回答