The multi-entry file configuration of
webpack automatically generates multiple entry files. As for html, it is not important, you can create it yourself, as long as the referenced js is correct, you can
A project on hand is the same. It belongs to a multi-entry project with 3 html files and 3 js entry files
config.jsHTMLDirshtml
.
the webpack config section mainly pays attention to the three items of HTMLPlugins,Entries,chunks
.
let HTMLPlugins = []
let Entries = {}
let chunks = []
config.HTMLDirs.forEach((page) => {
const htmlPlugin = new HtmlWebpackPlugin({
filename: `${page}.html`,
template: path.resolve(__dirname, `../src/html/${page}.html`),
chunks: ['manifest','vendor', page],
inject: true,
ssUrl: config.dev.SS_URL
});
HTMLPlugins.push(htmlPlugin);
Entries[page] = path.resolve(__dirname, `../src/js/${page}.js`);
})
//
plugins:[
//
...HTMLPlugins,
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: chunks,
minChunks:3
}),
]
as for login jumping to index, it is OK to directly window.location.href = 'index.html', because it is a simple page jump, and there is no page routing
.
it is recommended to make dynamic reading similar to the second floor, instead of manually configuring multi-entry
.