components icon indicating copy to clipboard operation
components copied to clipboard

MomentJS cannot be optimized and the moment-date-adapter is causing increased bundle size

Open realharry opened this issue 6 years ago • 6 comments

Reproduction

Steps to reproduce:

  1. Add a dependency on MatMomentDateModule on your angular app.
  2. Build the app with ng build --prod.
  3. Notice the increase in the output bundle size.

Screenshot of webpack-bundle-analyzer of the main bundle (built with --stats-json):

Stats - Screenshot from 2020-03-02 19-10-41

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

realharry avatar Mar 03 '20 03:03 realharry

It would be great if MatMomentDateAdapter could work with moment-mini

marko164 avatar Mar 04 '20 11:03 marko164

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

eduardocereto avatar May 19 '20 14:05 eduardocereto

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)

devversion avatar May 26 '20 09:05 devversion

Related feature request for date-fns Adapter: https://github.com/angular/components/issues/10278. PRs wanted for this.

Splaktar avatar Jul 22 '20 21:07 Splaktar

Tracking providing official alternatives to moment in #20599

jelbourn avatar Sep 17 '20 22:09 jelbourn

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.