Using split chunks plugin with the following config :
{
entry: {
entry1: [entry1.js],
entry2: [entry2.js],
entry3: [entry3.js],
...
}
optimization: {
splitChunks: {
chunks: "all"
}
}
}
The code would get perfectly split into:
vendors-entry1-entry2-entry3.js // common for all
vendors-entry1-entry3.js // vendors only required by both entry1, entry3
entry1-entry2.js // common code of entry1 and entry2
entry1.js // unique entry's code
entry2.js
entry3.js
Question is, how do i now use the specific vendors per entry in my html (or ejs in my specific case)?
Using HtmlWebpackPlugin as recommended would simply create an index.html which loads all of the above, although the use case is clearly:
When rendering entry1 page - load:
vendors-entry1-entry2-entry3.js
vendors-entry1-entry3.js
entry1-entry2.js
entry1.js
When rendering entry2 page - load:
vendors-entry1-entry2-entry3.js
entry1-entry2.js
entry2.js
etc..
CommonsChunkPlugin
has been removed in webpack 4.SplitChunksPlugin
is it's successor. – Guardado