I'm trying to configure tree shaking for our bundles using webpack. I'm looking to replace lodash with lodash-es. I know there are webpack plugins that will enable lodash tree-shaking but I'm looking to go straight to lodash-es cause our webpack configuration is a little complex.
When I look at the bundle size, I notice that the bundle is a lot smaller when I import using absolute path like: import merge from 'lodash-es/merge' as opposed to using a named import like: import { merge } from 'lodash-es'.
Is this an expected behaviour or is this more indicative of tree-shaking not being configured properly?
This should be tree shaken correctly:
lodash-es/package.jsonsetssideEffects: false, at least in the current versionOther things you can check:
babelor some other tool turning your es-module into something that doesn't work with treeshaking.