(Late) FeatureRequest: Provide means to tame a bit dynamic requires
See original GitHub issueI know it is quite late for such things but recently this problem has hit me (and as I see not even me).
Versions.
@angular/cli: 1.0.0-rc.0
Repro steps.
Added to package.json
following dependencies
"dependencies": {
"moment": "^2.17.1"
}
When I hit $ ng build
, my vendor file size blows up 😉
This is due to the fact that moment.js has dynamic require for locales and when combined with webpack it results in pulling everything to the build. Known solution of this problem (as mentioned in the sources below) is to get those excluded by use of ContextReplacementPlugin or IgnorePlugin, but there is no way (at least I couldn’t find any) to use any of those without ejecting myself. Would be great to have some means to put a bit of control over such requires without need of ejecting. Or if you know the way how to do this please close this issue and share it on SO.
References
Marco Rinck posted same problem on SO: How to exclude dependencies from webpack in a angular-cli project There is solution for plain webpack on SO: How to prevent moment.js from loading locales with webpack? webpack issue #198 webpack issue #87
Thanks in advance!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:17
- Comments:12 (9 by maintainers)
the fix is to use datefns, which is modular: https://date-fns.org See my comment here for a difference in bundle size and how to switch: https://github.com/angular/angular-cli/issues/2496#issuecomment-274272747
The suggested hack by @filipesilva does not work in my angular-cli project (in the linked comment you see that you are supposed to also delete node_modules/moment/src). My bundle still contain 212 kb of momentjs and all locales.
@intellix yes that does the trick for your own code which is my preferred solution too. In my case I used charts.js which imports momentjs by itself and I can’t change that (besides not using charts.js)