注意的是需要 new 两个 HtmlWebpackPlugin()
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
//多入口
mode: 'production',
entry: {
home: './src/index.js',
other: './src/other.js'
},
output: {
// [name] 表示 home 和 other
filename: '[name].js',
path: path.join(__dirname, './dist')
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
filename: 'home.html',
chunks:['home']
}),
new HtmlWebpackPlugin({
template: 'index.html',
filename: 'other.html',
chunks:['other']
}),
],
}
本文详细介绍了如何使用Webpack进行多页面应用的配置,通过new两个HtmlWebpackPlugin实例,实现不同入口文件对应不同HTML模板的打包。具体包括配置多入口、设置输出文件名、使用插件自动生成HTML文件等关键步骤。
444

被折叠的 条评论
为什么被折叠?



