角度ng生成与ng服务效果 [英] Angular ng build vs. ng serve performance
问题描述
如果 ng服务
工作正常,为什么我们要进行 ng构建
,除了大小问题外,还有什么具体原因吗?
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
运行角度应用程序,并且对应用程序进行了任何更改,这些更改将被捕获并立即反映在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/).
这篇关于角度ng生成与ng服务效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!