简体   繁体   English

为什么我们需要在 angular prod 构建中设置“--aot false”?

[英]Why do we ever need to set "--aot false" in angular prod build?

I know that " ahead of time compilation " provides compilation at the build time.我知道“ ahead of time compilation ”在构建时提供编译。 There are also bunch of other advantages of --aot such as --aot还有许多其他优点,例如

  • the application is pre-compiled so there is no such a wait template应用程序是预编译的,所以没有这样的等待模板

  • binding errors will be known at build time etc..绑定错误将在构建时等已知。

However, there is also an option to set --aot to false (for the prod build as well).但是,还有一个选项可以将--aot设置为 false(对于 prod 构建也是如此)。 Why do we ever need to set --aot to false ?为什么我们需要将--aot设置为false In other word, what kind of advantage does --jit provides?换句话说,-- --jit提供了什么样的优势? I just want to understand if there is any disadvantage of using --aot over --jit because otherwise, it sounds like I should always use --aot even in dev build.我只是想了解使用--aot不是--jit是否有任何缺点,因为否则,即使在开发版本中,听起来我也应该始终使用--aot And if there is no trade-off by using --aot , then why it is not set as default for the ng build and ng serve ?如果使用--aot没有权衡,那么为什么不将其设置为ng buildng serve默认值?

As @Ingo Burk mentioned in the comment, I end up with same findings so I wanted to post it as an answer.正如@Ingo Burk 在评论中提到的,我最终得到了相同的发现,所以我想将其发布为答案。

Also other interesting thing I found out was,我发现的另一个有趣的事情是,

However In version 5 and later, the compiler automatically performs this rewriting while emitting the .js file但是在版本 5 及更高版本中,编译器在发出 .js 文件时会自动执行此重写

AOT is good in terms of performance as code is complied much before loading to the browser as in JIT. AOT 在性能方面是好的,因为代码在加载到浏览器之前像 JIT 一样被编译了很多。 It is now byDefault available after Angular 8. @CuriousBOy and @Ingo mention a few use cases where Jit is preferred.它现在在 Angular 8 之后默认可用。@CuriousBOy 和 @Ingo 提到了一些首选 Jit 的用例。

One More use case I want to add for dynamic component and module rendering .我想为动态组件和模块渲染添加的更多用例。

If you need to create the component at runtime and want to render it you might need JIT in Browser, because AOT will not be able to compile the code as the Dynamic component and Dynamic module are not available at the build time .如果您需要在运行时创建组件并想要渲染它,您可能需要在浏览器中使用 JIT,因为 AOT 将无法编译代码,因为动态组件和动态模块在构建时不可用

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

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