Angular CLI - why is the <ng serve> package better than the <ng build>?

Running a series of Angular CLI commands to create a standard base project:

ng new project cd project ng build --prod 

... as a result, I get a generated dist folder with several packages. The largest is called vendor.[hash].js and the size is about 855kB .

However, if I run ng serve --prod instead:

 ng new project cd project ng serve --prod 

... I see that the weight of localhost:4200 loaded by the provider is around 300kB using the Chrome console.

Why is this happening? Is there a way to achieve a second result without ng serve , but rather with ng build ?

+6
source share
3 answers

As it was discovered in the comments, you simply compared two different values: the file size without gzip in the file system and the size of the loaded gzipped in the browser console.

+4
source

It's not about which one is better.

All about when to use build or maintain .

  • build is used for deployment, and is used for development purposes.
  • build generates compiled output to the / dist directory and maintain the collection of artifacts from memory for faster development.

Link: build vs. serve

+2
source

I tested this in my environment:

ng build --prod = main. [hash] .js = 792KB.

bg serve --prod = main. [hash] .js = 863KB.

 $ ng --version angular-cli: 1.0.0-beta.19-3 node: 7.0.0 os: win32 x64 

ng serve generates a slightly smaller cache file because it is temporary.

Update your ng cli and check again.

0
source

Source: https://habr.com/ru/post/1013660/


All Articles