给出类似
的输入/输出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
答案 0 :(得分:2)
您是否尝试过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
})
]