My webpack configuration has a "common" chunk that's used by multiple entry points. In addition to containing code used by multiple entry points, I'd like this to also call a function on load.
I tried making a "common" entry point with the same name as the chunk, but though I can see the common file's content in the generated output, it doesn't run on load.
I assume this is because of the following, from Webpack's splitChunksPlugin documentation:
If the splitChunks.name matches an entry point name, the entry point will be removed.
Is there a way around this, to get a "common" chunk to run something on load?
My webpack config's entry is:
entry: {
common: './src/entryPoints/common.tsx',
entry1 './src/entryPoints/entry1.tsx',
entry2: './src/entryPoints/entry2.tsx'
}
and its optimisation.splitChunks is:
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'all',
minChunks: 2,
priority: 1,
enforce: true
},
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
priority: 3,
}
}
}
For test purposes, common.tsx just contains:
import '../misc/polyfills';
console.log('COMMON ENTRY POINT');
Thanks in advance.