角度:ngc或tsc? [英] Angular: ngc or tsc?

查看:120
本文介绍了角度:ngc或tsc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用tsc,但是看到angular.io强调了ngc。我想知道这两者是否有优势,还是我应该选择一个。

I have been using tsc, but see that angular.io emphasizes ngc. I am wondering if there are advantages to either or if I should choose one over the other. Thanks in advance.

推荐答案

tsc和ngc具有不同的用途,而不是一个选择。

tsc and ngc have different purposes and it's not about selecting one over the other.

tsc是TypeScript编译器,如果您的应用程序是用TypeScript编写的,则需要它来生成JavaScript。

tsc is a TypeScript compiler, and you need it to generate JavaScript if your app is written in TypeScript.

ngc是Angular特定的编译器。它不会将TypeScript代码转换为JavaScript。它起到了画龙点睛的作用,使您的应用程序捆绑包可供浏览器呈现。特别是,它将组件模板转换为嵌入式JavaScript。如果您使用Ahead of Time(AoT)编译进行产品构建,则ngc会在构建捆绑包之前发挥作用。在开发人员模式下,我们使用即时编译:模板未预先编译,捆绑包中包含ngc编译器,浏览器加载捆绑包后便会编译模板。

ngc is an Angular-specific compiler. It doesn't turn the TypeScript code into JavaScript. It does a "finishing touch" to make your app bundles ready for rendering by the browser. In particular, it turns your components templates into inline JavaScript. If you do a prod build with Ahead of Time (AoT) compilation, the ngc does its part before the bundles are built. In dev mode we use Just-in-Time compilation: the templates are not precompiled, the ngc compiler is included into the bundles, and it compiles the templates after the browser loaded your bundles.

这篇关于角度:ngc或tsc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆