使用 `ng serve --aot=true` 的应用程序编译时间比仅使用 `ng serve` 花费更多时间

app compiler time with `ng serve --aot=true` takes more time than just `ng serve`

我的 angular 应用程序,我有 no.of 个模块。当我用 html 或 css 更改某些内容时,重新编译需要时间。所以我决定从 ng serve --aot=true 开始,但我发现 运行 应用程序与没有任何标志的 ng serve 相比需要更多时间。但是这里有什么问题或者 ng serve --aot=true 的目的是什么?

任何人都可以帮助我理解 ng serve --aot=true 标志。

Angular 提供了 2 种方法来绑定您的应用程序:

Just-in-Time (JIT),它会在 运行 时间在浏览器中编译您的应用程序。 (当你 运行 ng serve

  • 在浏览器中编译
  • 每个文件单独编译
  • 无需在更改代码后和重新加载浏览器页面之前构建
  • 适合本地发展

Ahead-of-Time (AOT),它会在构建时编译您的应用程序。 (当你 运行 ng serve --aot=true

  • 机器自己编译,通过命令行(更快)
  • 所有代码一起编译,在脚本中内联HTML/CSS
  • 无需部署编译器
  • 适合生产构建

The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default.

The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.

由于 JIT 在 运行 时间编译您的应用程序,它可以优化编译并仅构建必要的代码。所以在开发模式下,通常使用 JIT 来节省完整构建的时间。使用 JIT 编译时间会更快。

AOT优化了运行ning的速度,但是编译时间较长,所以在生产中比较常用。 AOT 还将优化您的应用程序的大小,因为所有文件都将在 运行 编译它之前进行编译。