I've been looking at webpack bundling strategies and found a pretty good guide here: https://hackernoon.com/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758
It seems to advocate that lots of individual files is (often) the best way to go. I've followed along and created a simple bundle consisting of a js file that imports flexslider:
import "flexslider"
$(window).on('load', function () {
$('.flexslider').flexslider({
});
});
Obviously flexslider lives in the node_modules folder and my webpack config is set up to split out npm packages:
runtimeChunk: 'single',
splitChunks: {
chunks: "all",
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
},
},
}
Now for this fairly simple scenario here is what webpack generated
Ignore core and main as these are other bundles.
homeUS was the file that did the flexslider import - In terms of my HomeUS.html am I meant to reference all of these js files? or are some internal to webpack and I just reference HomeUs.js and flexslider.js and it all just 'works'?
I'm assuming some of these are flexslider dependencies As you can probably tell I'm not a webpack expert - the idea seems to be that returning visitors would only have to download the individual npm packages if they had changed and not a huge 'vendor' bundle.
Thanks