Closed MickL closed 3 years ago
Ok, that makes sense. I will fix the readme and also the demo app to reflect this.
Thanks!
@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.
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!
The documentation says:
I did this and checked with
ng build --stats-json
and then usingwebpack-bundle-analyzer
to see full 512kb ngx-date-fns is imported: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: https://github.com/date-fns/date-fns/issues/2207