[英]Angular ng build vs. ng serve performance
If ng serve
is working fine, why should we go for the ng build
except size issues, is there any specific reason ? 如果
ng serve
工作正常,除了大小问题,我们为什么要进行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 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
命令有意用于快速,本地和迭代式开发,还用于从本地CLI开发服务器构建,监视和服务应用程序。 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. 此外,如果您使用
ng serve
运行角度应用程序,并且对应用程序进行了任何更改,则更改将被捕获并立即反映在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. ng build
和ng serve
命令都将在构建项目之前清除输出文件夹。
The main difference is – The ng build
command writes generated build artifacts to the output folder and the ng serve
command does not. 主要区别是–
ng build
命令将生成的构建工件写入输出文件夹,而ng serve
命令则不。 By default, the output folder is - dist/. 默认情况下,输出文件夹为-dist /。
Also the ng serve
builds artifacts from memory instead for a faster development experience. 此外,
ng serve
可以从内存中构建工件,从而获得更快的开发体验。 The ng build
command generates output files just once and does not serve them. ng build
命令仅生成一次输出文件,不提供输出文件。
The ng build --watch
command will regenerate output files when source files change. 当源文件更改时,
ng build --watch
命令将重新生成输出文件。 This --watch
flag is useful if you're building during development and are automatically re-deploying changes to another server. 如果在开发过程中进行构建,并且自动将更改重新部署到另一台服务器上,则此
--watch
标志很有用。
Refer this link for more information on Angular apps deployment. 请参阅此链接以获取有关Angular应用程序部署的更多信息。
conclusion 结论
`ng serve`
does not write build and it builds artifacts from memory instead for a faster development experience. 不编写构建,而是从内存构建工件,以获得更快的开发体验。
`ng build`
writes generated build artifacts to the output folder (by default is -dist/). 将生成的构建工件写入输出文件夹(默认为-dist /)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.