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.
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
|
I hope you are enjoying with this post! Please share with you friends. Thank you!!