简体   繁体   English

ng build 和 ng serve 有什么区别?

[英]What is difference between ng build and ng serve?

What is the difference between ng build and ng serve? ng build 和 ng serve 有什么区别? What exactly done or changes happen after ng build and ng serve?在 ng build 和 ng serve 之后究竟做了什么或发生了什么变化?

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运行 angular 应用程序,并且您对应用程序进行了任何更改,那么这些更改将被捕获并立即反映在 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 buildng 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 应用程序部署的更多信息,请参阅此链接

The ng build command writes generated build artifacts to the output folder (by default is -dist/). ng build命令将生成的构建工件写入输出文件夹(默认为 -dist/)。 The ng serve command does not write build and it builds artifacts from memory instead for a faster development experience. ng serve命令不编写构建,而是从内存构建工件,以获得更快的开发体验。

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.如果发现代码中有任何更改,它会自动构建并提供该代码。

1. ng serve - it helps angular code to serve automatically & provide hard reload mechanism 1. ng serve - 它帮助 Angular 代码自动提供服务并提供硬重新加载机制

2. ng build - the angular compiler will convert into JavaScript executable code for deployment in the dist folder. 2. ng build - angular 编译器将转换为 JavaScript 可执行代码以部署在 dist 文件夹中。

The ng build command writes generated build artifacts to the output folder (by default is -dist/). ng build 命令将生成的构建工件写入输出文件夹(默认为 -dist/)。 The ng serve command does not write build and it builds artifacts from memory instead for a faster development experience. ng serve 命令不编写构建,而是从内存构建工件,以获得更快的开发体验。

Yes, you can still run ng build.是的,您仍然可以运行 ng build。 But when you are writing code and want to see the changes simultaneously, then running ng serve would be more recommended但是当你在写代码并希望同时看到变化时,那么更推荐运行 ng serve

Read here and here在这里这里阅读


ng build构建

writes generated build artifacts to the output folder (generally dist folder).将生成的构建工件写入输出文件夹(通常是dist文件夹)。

ng serve服务

does not write build and it builds artifacts from memory instead of faster development experience.不编写构建,而是从内存构建工件,而不是更快的开发体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM