Performing a number of Angular CLI commands in order to build the minified basic project:
ng new project
cd project
ng build --prod
... as a result, I get the generated dist folder with a number of bundles. The largest one is called vendor.[hash].js and it's size about 855kB.
However, if I perform ng serve --prod instead:
ng new project
cd project
ng serve --prod
... I can see the loaded by localhost:4200 vendor's bundle weight is about 300kB using Chrome console.
Why is that happens? Is there a way to achieve the second result without ng serve but rather with ng build?
As was discovered through the comments, you simply compared two different values: the size of the non-gzipped file in the file system, and the size of the gzipped download in the browser console.
It's not about which one is better.
It's all about when to use build or serve.
Ref : build vs. serve
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With