What is the difference between ng build and ng serve? What exactly done or changes happen after ng build and ng serve?
-
7The `ng serve` is command launches the server, watches your files, and rebuilds the app as you make changes to those files. For `ng build` : Read in [link] https://angular.io/guide/deployment – ahkeno Nov 07 '17 at 06:55
6 Answers
The ng build
command is intentionally for building the apps and deploying the build artifacts.
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.
Also, if you running the angular app using ng serve
and if you make any changes to your app, the changes are captured and reflected instantaneously on the UI. This avoids starting and stopping the server again and again.
Both commands ng build
and ng serve
will clear the output folder before they build the project.
The main difference is – The ng build
command writes generated build artifacts to the output folder and the ng serve
command does not. By default, the output folder is - dist/
.
Also the ng serve
builds artifacts from memory instead for a faster development experience.
The ng build
command generates output files just once and does not serve them.
The ng build --watch
command will regenerate output files when source files change. This --watch
flag is useful if you're building during development and are automatically re-deploying changes to another server.
Refer this link for more information on Angular apps deployment.

- 3,633
- 1
- 25
- 35
-
My question, we manually type and run `ng serve` in dev's terminal. Do we need to type and run `ng build` in production server's terminal? – Bigeyes May 31 '19 at 11:02
-
`ng serve` is used (only) on developer's machine to be able to run the app with minimum resources. But when you are talking about deploying the app to an actual server, you will use `ng build` as this command will generate the necessary artifacts that will get deployed on the server. – RITZ XAVI May 31 '19 at 18:01
-
So run `ng build` command still on dev machine's terminal rather than server? – Bigeyes Jun 01 '19 at 02:03
-
Yes, you can still run ng build. But when you are writing code and want to see the changes simultaneously, then running ng serve would be more recommended. – RITZ XAVI Jun 02 '19 at 06:06
-
1
The ng build command writes generated build artifacts to the output folder (by default is -dist/). The ng serve command does not write build and it builds artifacts from memory instead for a faster development experience.

- 3,892
- 3
- 31
- 47

- 491
- 5
- 7
Simply
`ng build`
This command builds your app and deploys it.
`ng serve`
This command build, deploy, serves and every time watches your code changes. if find any change in code it builds and serves that code automatically.

- 1,765
- 8
- 18
1. ng serve - it helps angular code to serve automatically & provide hard reload mechanism
2. ng build - the angular compiler will convert into JavaScript executable code for deployment in the dist folder.

- 4,970
- 8
- 20
- 35

- 57
- 7
ng build
writes generated build artifacts to the output folder (generally dist folder).
ng serve
does not write and it builds artifacts from memory instead of a faster development experience.

- 1,308
- 1
- 18
- 31
-
10I think you got confused with `npm build` and `ng build`. `scripts` property defines commands for *npm*. (see: [https://docs.npmjs.com/misc/scripts#description](https://docs.npmjs.com/misc/scripts#description)). `ng build` is an **angular** command which compiles the application into an output directory.(see: [https://github.com/angular/angular-cli/wiki/build](https://github.com/angular/angular-cli/wiki/build)) – Sanju Sep 21 '18 at 07:56
The ng build command writes generated build artifacts to the output folder (by default is -dist/). The ng serve command does not write build and it builds artifacts from memory instead for a faster development experience.
Yes, you can still run ng build. But when you are writing code and want to see the changes simultaneously, then running ng serve would be more recommended

- 1
- 1