We are developing an application using Angular 5. After running the ng build --prod --aot and deployed the dist folder to the dev server the main bundle produced 2.2MB on initial load. It's already small compared to 8MB vendor bundle size (when running ng build --prod) but still, we need to lower the size of the main bundle. Is there any way to lower the size of the main bundle?
Asked
Active
Viewed 7,088 times
6
JonathanDavidArndt
- 2,518
- 13
- 37
- 49
Eugene
- 67
- 1
- 2
-
You can exclude node_modules folder from bundle. – Dheeraj Kumar Apr 06 '18 at 07:29
-
Can you provide `index.html` and `.angular-cli.json` files? – planet_hunter Apr 06 '18 at 08:40
-
Hi @ManojChalode Please see this [link](http://embed.plnkr.co/BN8gRUoeVQcaAnfbLAUr/) to see index.html and .angular-cli.json Thanks :) – Eugene Apr 08 '18 at 23:19
2 Answers
2
You can reduce the bundle size by adding build-optimizer flag to your build:
ng build --prod --build-optimizer
Try running the above command. For more info visit: https://angular.io/guide/deployment
AFAIK you need not have to include --aot flag when building using --prod. Production build is aot by default.
Updating to the latest version of angular is also a solution for this. Since latest version often comes with more optimized build procedures.
Gautam Krishna R
- 2,388
- 19
- 26
-
Hi Gautam, I tried to ran the command but the size main bundle still 2.3 MB – Eugene Apr 06 '18 at 07:34
-
Hi @Eugene then try using the steps provided in the following answer: https://stackoverflow.com/a/43358855/4214976 – Gautam Krishna R Apr 06 '18 at 07:37
-
Tried this command "ng build --aot --prod --build-optimizer=true --vendor-chunk=true" and it lowered the size from 2.3MB to 869KB. However it created a vendor file with the size of 1.7MB which I think still the same – Eugene Apr 06 '18 at 08:01
-
0
I believe you need to separate your code into modules and load them lazily.
Ramdane Oualitsen
- 402
- 5
- 13
