MomentJS cannot be optimized and the moment-date-adapter is causing increased bundle size
Reproduction
Steps to reproduce:
- Add a dependency on
MatMomentDateModuleon your angular app. - Build the app with
ng build --prod. - Notice the increase in the output bundle size.
Screenshot of webpack-bundle-analyzer of the main bundle (built with --stats-json):

Expected Behavior
Addition of a "simple" widget should not increase the output bundle size dramatically.
Actual Behavior
Huge increase in the bundle size, on the order of a few hundred kilobytes. (Over 338kb added by moment.js alone, in my example.)
Environment
- Angular: 9.0.4
- CDK/Material: 9.1.0
- Browser(s): N/A
- Operating System (e.g. Windows, macOS, Ubuntu): N/A
It would be great if MatMomentDateAdapter could work with moment-mini
moment.js unfortunately doesn't do well with tree shaking. Here are some extra info on alternatives that do.
https://github.com/you-dont-need/You-Dont-Need-Momentjs
Thanks for this issue. We are aware of the limitations with MomentJS. We should really document the bundle size implications with the moment date adapter. Additionally it might be good to provide a better integrated date adapter (one that can be more optimized).
We have various proposals for other date adapters (such as date-fns or day.js)
Related feature request for date-fns Adapter: https://github.com/angular/components/issues/10278. PRs wanted for this.
Tracking providing official alternatives to moment in #20599
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.