将单独的入口点脚本分配给单独的 HtmlWebpackPlugin 实例

Assign separate entrypoint scripts to separate HtmlWebpackPlugin instances

给定一个 entry/output 喜欢

entry: {
    app: 'src/client/app.js',
    unauthApp.js: 'src/client/unauth.js'
  },
output: {
  path: 'dist',
  filename: 'scripts/[name]-[chunkhash].js'
},
...
plugins: [
  new HtmlWebpackPlugin({
    filename: 'views/index.html'
  }),
  new HtmlWebpackPlugin({
    filename: 'views/index-inauth.html'
  })
]

是否可以使用 HtmlWebpackPlugin 的两个实例将 app 脚本放入一个模板,将 unauthApp 脚本放入另一个模板。到目前为止,我所能做的就是将两个脚本都放入其中。我也在玩 htmlWebpackTemplate 所以也许有一个我没见过的选项。

webpack@^4.6.0

您尝试过 chunks 字段吗?它Allows you to add only some chunks (e.g only the unit-test chunk)

plugins: [
  new HtmlWebpackPlugin({
    filename: 'views/index.html',
    chunks: ['app'],
    inject: true
  }),
  new HtmlWebpackPlugin({
    filename: 'views/index-unauth.html',
    chunks: ['unauthApp.js'],
    inject: true
  })
]