date-fns: esm tree-shaking not working
The docs show an esm import like this:
import { isValid } from 'date-fns';
When bundling this code using webpack, it causes 100% of the date-fns code to be included in the bundle causing the bundle size to increase by approx 82KiB
To reduce the bundle size (tree-shaking), the import must be done like this:
import isValid from 'date-fns/isValid';
date-fns: 2.0.0-beta.5 webpack: 4.39.2
See webpack-bundle-analyzer report:
Some useful info on the equivalent issue importing Icons from Material-UI: https://material-ui.com/guides/minimizing-bundle-size/
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (10 by maintainers)
@KevinSheedy Though your current setup just works for me (I removed
externalsoption). The result is 1985 bytes. Don’t see any problem.