I'm using Dynamic imports with Webpack, as per the documentation: https://webpack.js.org/guides/code-splitting/#dynamic-imports
Very basic example (not actual code):
// main.js
import('./moduleA).then((moduleA) => {
moduleA.init();
});
import('./moduleB).then((moduleB) => {
moduleB.init();
});
// moduleA.js
import utility from './utility';
export function init() {...}
// moduleB.js
import utility from './utility';
export function init() {...}
The problem is that the utility module is included in both moduleA and moduleB chunks, so it's duplicated. I can't find a way to get Webpack to split these types of dependencies into a separate common chunk like it does with standard imports. The SplitChunksPlugin doesn't seem to bundle any common dependencies between moduleA and moduleB because they're imported dynamically. Any ideas, please?