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

Created on 3 Mar 2020  路  6Comments  路  Source: angular/components

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
P3 materiadatepicker

Most helpful comment

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)

All 6 comments

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xtianus79 picture xtianus79  路  3Comments

RoxKilly picture RoxKilly  路  3Comments

constantinlucian picture constantinlucian  路  3Comments

Miiekeee picture Miiekeee  路  3Comments

MurhafSousli picture MurhafSousli  路  3Comments