Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between ng build and ng serve?

What is the difference between ng build and ng serve? What exactly done or changes happen after ng build and ng serve?

like image 221
Dnyanesh Avatar asked Nov 07 '17 05:11

Dnyanesh


People also ask

Does ng Serve use NG build?

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. This command builds your app and deploys it.

What does ng serve mean?

ng serve is a great command to use when developing your application locally. It starts up a local development server, which will serve your application while you are developing it. It is not meant to be used for a production environment.

What is NG build in angular?

ng build is the command you use when you're ready to build your application and deploy it. The CLI will analyze the application and build the files, all while optimizing the application as best as it can.

What is difference between ng build and NPM build?

NPM is basically a package manager which acts as a dependency provider. If there are many small packages, required to build a large one, NPM is the one hotspot which will provide us with the packages. Angular-CLI is one of those packages. As far as NG is concerned, it is the core module of Angular.

What is the difference between Ng serve and build in angular?

ng serve command builds the angular application in the memory, without saving the artifacts to any external folder and runs the application on the web server. ng build command builds the angular application and generates the build artifacts which are saved under the /dist folder in the application directory.

What is the use of Ng serve command?

The ng serve command does not write build and it builds artifacts from memory instead for a faster development experience. This command builds your app and deploys it. 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.

Is it still possible to run ng build command?

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. Where do i can see output folder when executes ng serve command?

What is the output folder of ng build?

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.


1 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.

like image 197
RITZ XAVI Avatar answered Sep 22 '22 04:09

RITZ XAVI