Angular Ng Build vs Ng Serve Commands

ng build vs. ng serve Commands in Angular 4/5

What Are Difference Between ng build and ng serve Commands?
The ng build command is intentionally for building the apps and deploying the build artefacts.

ng build


The ng serve command is intentionally for fast, local and iterative developments and also for builds, watches and serves the application from a local CLI development server.

ng serve


Both commands ng build and ng serve - clear the output folder before they build the project.

The main difference is – “The ng build command writes generated build artefacts to the output folder and the ng serve command does not writes build and the ng serve build artefacts from memory instead for a faster development experience.”

The by default output folder is - dist/

The ng build --watch command is used to regenerate output files when source files change and the --watch flag is useful when we are building during development and it automatically re-deploying changes to another server.

ng build --watch


These options also apply to the serve command. If you do not pass a value for environment, it will default to dev for development and prod for production.

//These are equivalent
ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod


And
//And these are
ng build --target=development --environment=dev
ng build --dev --e=dev
ng build --dev
ng build


The --dev vs --prod builds tables looks like -

Flags
--dev
--prod
--aot
false
true
--environment
dev
prod
--output-hashing
media
all
--sourcemaps
true
false
--extract-css
false
true
--named-chunks  
true
false
--build-optimizer
false
true with AOT and Angular 5
















I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

ng build vs. ng serve Commands in Angular 4/5 ng build vs. ng serve Commands in Angular 4/5 Reviewed by Anil Singh on 2:10 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^