I have setup entries in webpack config as
entry: {
// main: './src/index.js',
analytics: './src/analytics/index.js',
};
since the main entry is commented out I expected some modules not to be included in the bundle but were still being added. It turns out both entries eventually import some stuff from a file that re-exports a lot of the unwanted and wanted modules. Why aren't such unused exports excluded from the bundle?
After going through the tree-shaking documentation I can confirm that
- We use ES2015 module syntax (i.e. import and export).
- @babel/preset-env is configured with modules: false, other babel presets we use are @babel/preset-react and @babel/preset-typescript
- not sure if sideEffects should be set in package.json as we are not publishing the project as package, I am okay with third-party libraries not being tree-shaken.
optimization.sideEffectsshould be true by default. - production mode is enabled