My project user angular version 7, and here is the angular.json configuration
when I build for production my main.js file is way too large nearly 12MB in size which makes my app to load the page very slowly. Nearly the initial load tooks 4 - 5 minutes
Here is the build result
Here is my analyser result
Thanks in advance
Angular is a very opinionated and robust framework. As a result, Angular apps generally have bigger bundle sizes when compared to apps written using other JavaScript frameworks like React. The Angular framework comes with a lot of useful libraries already included within it, such as RxJs and Zone.
I checked many apps built with Angular and have a feeling that most medium size enterprise apps should have main. *. js under 500 KB, on average 250KB. If your bundle size largely exceed those numbers, you may need to be aware.
main. js : your application code and everything you have imported. vendor. js : third-party code that your application depends on.
Split the file which is taking too much into modules and apply lazy loading
First of all, stop using webpack bundle analyzer because it does not give accurate representation of your bundle space and start using source-map-explorer.
As per the Angular docs, if you import any thing outside of lazy loaded module, then it will be included in your main.js bundle. I had this issue where I was importing shared module in every module and shared module itself imported a lot of packages from node_modules
which led to an increase in main.js file.
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