What is difference between ng build and ng serve?

北城以北 提交于 2020-04-07 13:46:25

问题


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


回答1:


Update:

Read this document https://docs.npmjs.com/misc/scripts#description


The ng build is to build artifacts.

The ng serve command is to pre-install packages and start the app.




回答2:


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:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/47150724/what-is-difference-between-ng-build-and-ng-serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!