Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: ngc or tsc?

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.

like image 408
David Streid Avatar asked May 01 '18 03:05

David Streid


People also ask

What is TSC Angular?

TypeScript is a primary language for Angular application development. It is a superset of JavaScript with design-time support for type safety and tooling. Browsers can't execute TypeScript directly. Typescript must be "transpiled" into JavaScript using the tsc compiler, which requires some configuration.

What is NGC Angular?

The Angular Compiler (which we call ngc ) is the tool used to compile Angular applications and libraries. ngc is built on the TypeScript compiler (called tsc ) and extends the process of compiling TypeScript code to add additional code generation related to Angular's capabilities.

What is TSC TypeScript?

Tsc stands for `TypeScript compiler` and is a simple tool included in Typescript itself, allowing you to compile any ts files into js.

Does Angular use AOT by default?

By default, aot is set to true for new CLI applications. See the CLI command reference and Building and serving Angular apps for more information.


1 Answers

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

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

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.

like image 171
Yakov Fain Avatar answered Sep 27 '22 19:09

Yakov Fain