修改入口和出口配置
在 webpack.config.js 中修改入口与出品配置
entry: {
main: './src/main.js',
other: './src/other.js'
},
output: {
path: path.join(__dirname, './dist/'),
// 多入口无法对应一个固定的出口,所以修改 filename 为[name]变量
filename: '[name].js',
publicPath: '/'
},
plugins: [
// 如果用了 html 插件,需要手动配置多入口对应的html 文件,将指定其对应的输出文件
new HtmlWebpackPlugin({
template: './src/main.html',
filename: 'main.html',
chunks: ['main'] // 可以写多个值,决定引入哪几个 js, 值由 entry 的key值决定
}),
new HtmlWebpackPlugin({
template: './other.html',
filename: 'other.html',
chunks: ['other']
})
]
修改入口对象,支持多个 js 入口,同时修改output 输出的文件名为 '[name].js'
表示自己入口文件名作为输出文件名,但是 html-webpacl-plugin 不支持此功能,所以需要再 new 一个插件,用于生成两个 html 页面,实现多页应用。