23

Angular CLI creates vendor.js and I don't know Why and What is the use of it?? Size of this file is about 3.2MB for a new app!!

Does this file contains Angular 6 Javascript Source?

Don't you think this is big file for loading on internet on low speed connections?

Mohamad Shiralizadeh
  • 7,153
  • 5
  • 52
  • 78

4 Answers4

29

You mean how to decrease? This file includes all libraries that you added into your project. If you build your app on production mode it'll be much lower.

ng build --prod

If it's not your answer, explain more what you are looking for.

molikh
  • 1,065
  • 10
  • 24
21

Try

ng build --prod --aot --vendor-chunk --common-chunk --delete-output-path --buildOptimizer

I reduced my vender.**.js fromm 12mb to 2mb

DV Singh
  • 681
  • 5
  • 13
8

Instead of decreasing it you can remove the file completely By specifying the --build-optimizer flag, the cli will disable this file from the build output.

The CLI will now bundle the vendor code into the main.js bundle, which will also enable uglification to reduce the size.

So you will see a small increase in the size of the main.js bundle which is minimal in comparison to the size of the vendor chunks

Nanotron
  • 444
  • 4
  • 11
5

You may also want to update your build script in package.json to generate a prod build by default. I ran into this deploying to Heroku, since it runs 'npm build' automatically. By default, 'npm build' runs the following script:

ng build

If you update it to

ng build --prod

in package.json, then Heroku/AWS/Azure will create a production build on deployment instead.

Evan Kleiner
  • 142
  • 1
  • 9