Assign separate entrypoint scripts to separate HtmlWebpackPlugin instances

橙三吉。 提交于 2019-12-06 13:16:54

问题


Given an entry/output like

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'
  })
]

is it possible using two instances of HtmlWebpackPlugin to put the app script into one template and the unauthApp script into the other. So far all I have been able to do is put both scripts in both. I'm also playing with using htmlWebpackTemplate so perhaps there is an option there I have not seen.

webpack@^4.6.0


回答1:


Have you tried the chunks field? It 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
  })
]


来源:https://stackoverflow.com/questions/50163019/assign-separate-entrypoint-scripts-to-separate-htmlwebpackplugin-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!