分配单独的入口点脚本以分隔HtmlWebpackPlugin实例 [英] Assign separate entrypoint scripts to separate HtmlWebpackPlugin instances
本文介绍了分配单独的入口点脚本以分隔HtmlWebpackPlugin实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定输入/输出
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
所以也许有一个我没见过的选项。
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
推荐答案
你试过块
字段?它允许你只添加一些块(例如只有单元测试块)
plugins: [
new HtmlWebpackPlugin({
filename: 'views/index.html',
chunks: ['app'],
inject: true
}),
new HtmlWebpackPlugin({
filename: 'views/index-unauth.html',
chunks: ['unauthApp.js'],
inject: true
})
]
这篇关于分配单独的入口点脚本以分隔HtmlWebpackPlugin实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文