MomentJS cannot be optimized and the moment-date-adapter is causing increased bundle size
See original GitHub issueReproduction
Steps to reproduce:
- Add a dependency on
MatMomentDateModule
on 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cannot find module '@angular/material-moment-adapter'
I try importing the MomentDateAdapter as shown on the angular website but Visual Studio Code keeps complaining it cant find @angular/material- ...
Read more >Docs - Moment.js
Moment doesn't work well with modern "tree shaking" algorithms, so it tends to increase the size of web application bundles.
Read more >How We Managed to Shed 300kb of Moment.Js Size in Angular
I analyzed my generated build with source-map-explorer and got the following treemap. I observed that my build size increased by 364KB with ...
Read more >DayJS: The best lightweight alternative to momentjs
momentJS vs DayJS? import cost; Bundle Size. DayJS; MomentJS; Minimal Project (without any external library aside from boilerplate). Performance.
Read more >angular/material-moment-adapter - npm
Keywords · Install · Repository · Homepage · Weekly Downloads · Version · License · Unpacked Size · Total Files.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
orday.js
)Tracking providing official alternatives to moment in #20599