首页 > 解决方案 > Angular 12 中的 AOT 编译

问题描述

Angular 文档指出:

 *Ahead-of-Time (AOT), which compiles your application and libraries at build time. This is the 
 default since Angular 9.*

因此,如果我想使用 AOT 为生产编译我的 Angular 12 应用程序,我只需要键入ng build而不添加--prod并且既不在angular.json也不在package.json中添加特定配置?

这是我的 package.json中的ng build命令:

...
"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prepare": "husky install"
  },
...

谢谢你的帮助

标签: angularbuildaotangular-aot

解决方案


您不需要明确包含--prod用于生产构建的命令 - 假设您使用的是最新版本的 Angular,即我收集的 v12。

默认的 angular.json 文件包含有关生产构建的配置文件部分,您可以保持原样。


推荐阅读