question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Late) FeatureRequest: Provide means to tame a bit dynamic requires

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:17
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
intellixcommented, Mar 16, 2017

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

1reaction
marcorinckcommented, Mar 19, 2017

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make a Feature Request - Later Help Center
Important: Search for your idea first, before creating a new one. The more votes that an idea has, the more we know that...
Read more >
112db EQ is out - Page 7 - Effects Forum - KVR Audio
And yes, plug-in delay compensation is set to All. ... Feature request noted! ... not the only feature that requires latency--the dynamic EQ...
Read more >
Product Feature Requests - How to Write and Submit Them
Describes the Feature Request process and provides tips on how to write a Feature Request for best results.
Read more >
Component testing scenarios - Angular
The following discussion covers testing components that require the router. The immediate goal is to test the DashboardHeroComponent , not the ...
Read more >
dynamic VI calls | Not a Tame Lion
Because the user-defined inputs could change at any time, the decision was made to make the acquisition loops event-driven, and create a separate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found