Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation about tree shaking is not correct #355

Closed
MickL opened this issue Mar 9, 2021 · 2 comments
Closed

Documentation about tree shaking is not correct #355

MickL opened this issue Mar 9, 2021 · 2 comments
Labels

Comments

@MickL
Copy link

MickL commented Mar 9, 2021

The documentation says:

The library itself is optimized to be tree-shakable by just importing DateFnsModule.forRoot()

I did this and checked with ng build --stats-json and then using webpack-bundle-analyzer to see full 512kb ngx-date-fns is imported:

Bildschirmfoto 2021-03-09 um 12 59 55

But when I import just the specific pipe it works and ngx-date-fns is not even visible.

Dont try to reproduce with something newer than 2.16.1 since newer versions do not support tree shaking in the first place: date-fns/date-fns#2207

@joanllenas
Copy link
Owner

Ok, that makes sense.
I will fix the readme and also the demo app to reflect this.

Thanks!

@joanllenas
Copy link
Owner

@MickL I tested the bundle size with webpack-bundle-analyzer as you suggested but I think it's not working properly.
The command used to test tree shaking in this project is npm run analyze:app which uses source-map-explorer, and if you double-check with the actual main.js size, it makes sense.

date-fns v2.19.0

Screenshot 2021-03-14 at 13 17 12
Screenshot 2021-03-14 at 14 01 34

date-fns v2.16.1

Screenshot 2021-03-14 at 14 10 19
Screenshot 2021-03-14 at 13 56 39

Issues with webpack-bundle-analyzer

I don't know the exact details about why the tool is not working properly, but I found a couple of places where they recommend aginst using it for Angular:

(source)

While the Angular CLI uses Webpack for some of its bundling, it also makes additional optimizations on top of Webpack. Because of these optimizations, it's important to use the source-map-explorer to test the final output and not the webpack-bundle-analyzer that is commonly used with Webpack based applications.

(source)

The angular team strongly recommends to only use source-map-explorer to analyze your bundle size instead of webpack-bundle-analyzer. According to them, webpack-bundle-analyzer and a few other similar tools doesn't give the actual info pertaining to angular build process.

Thanks for taking the time to explore this issue and for the v2.16.1 issue finding. I will add a note to the readme.
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants