Angular ng build vs. ng serve 性能 [英] Angular ng build vs. ng serve performance
问题描述
如果 ng serve
工作正常,除了大小问题,我们为什么要使用 ng build
,有什么具体原因吗?
If ng serve
is working fine, why should we go for the ng build
except size issues, is there any specific reason ?
我知道 ng build
将生成的构建工件写入输出文件夹,但我想知道是否存在任何性能差异.
I know that ng build
writes generated build artifacts to the output folder but I want to know if there is any performance difference.
推荐答案
ng build
命令专门用于构建应用程序和部署构建工件.
The ng build
command is intentionally for building the apps and deploying the build artifacts.
ng serve
命令专门用于快速、本地和迭代开发,也用于从本地 CLI 开发服务器构建、监视和服务应用程序.此外,如果您使用 ng serve
运行 angular 应用程序,并且您对应用程序进行了任何更改,则更改会被捕获并立即反映在 UI 上.这避免了一次又一次地启动和停止服务器.
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.
ng build
和 ng serve
这两个命令都将在构建项目之前清除输出文件夹.
Both commands ng build
and ng serve
will clear the output folder before they build the project.
主要区别在于 - ng build
命令将生成的构建工件写入输出文件夹,而 ng serve
命令不会.默认情况下,输出文件夹是-dist/.
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/.
此外,ng serve
从内存中构建工件,以实现更快的开发体验.ng build
命令只生成一次输出文件并且不提供它们.
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.
ng build --watch
命令将在源文件更改时重新生成输出文件.如果您在开发过程中构建并自动将更改重新部署到另一台服务器,则此 --watch
标志非常有用.
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.
有关 Angular 应用部署的更多信息,请参阅此链接.
Refer this link for more information on Angular apps deployment.
结论
`ng serve`
不编写构建,而是从内存构建工件,以获得更快的开发体验.
does not write build and it builds artifacts from memory instead for a faster development experience.
`ng build`
将生成的构建工件写入输出文件夹(默认为 -dist/).
writes generated build artifacts to the output folder (by default is -dist/).
这篇关于Angular ng build vs. ng serve 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!