Angular 5 - Main bundle file is too large on the development server
Asked Answered
M

2

6

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?

network

Mcclary answered 6/4, 2018 at 7:27 Comment(3)
You can exclude node_modules folder from bundle.Illbred
Can you provide index.html and .angular-cli.json files?Creep
Hi @ManojChalode Please see this link to see index.html and .angular-cli.json Thanks :)Mcclary
N
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.

Noneffective answered 6/4, 2018 at 7:30 Comment(4)
Hi Gautam, I tried to ran the command but the size main bundle still 2.3 MBMcclary
Hi @Mcclary then try using the steps provided in the following answer: https://mcmap.net/q/135909/-how-to-decrease-prod-bundle-sizeNoneffective
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 sameMcclary
--aot and --build-optimizer are suprlus when using --prodImportant
S
0

I believe you need to separate your code into modules and load them lazily.

Sideburns answered 18/1, 2019 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.