跳到主要内容

多页面配置

  • 多页应用 需要配置多个入口entry
  • 配置html-webpack-plugin
    • 指定chunk, 将页面的js注入到当前html里面
json
module.exports = {
entry: {
'page1': './src/pages/page1/app.js', // 页面1
'page2': './src/pages/page2/app.js', // 页面2
},
plugins: [
new HtmlWebpackPlugin(
{
template: './src/pages/page1/index.html',
chunks: ['page1'],
}
),
new HtmlWebpackPlugin(
{
template: './src/pages/page2/index.html',
chunks: ['page2'],
}
),
]
}