6

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.

David Streid
  • 685
  • 3
  • 12
  • 24

1 Answers1

20

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.

Yakov Fain
  • 11,972
  • 5
  • 33
  • 38
  • 2
    This answer explains very clearly, in just a 'few' lines of text, what a 1000 pages of official documentation for some reason cannot. I could never for the life of me find out the exact roles of TSC and NGC within the Angular2+ story, how they relate to one another and whether or not one rules out the other. So thanks a lot for your answer :) – Kornelis Mar 21 '19 at 14:53
  • 2
    @Kornelis I'm glad it was useful for you :) – Yakov Fain Mar 22 '19 at 16:09
  • So If i release my Angular app on Tomcat or on IIS server, it will use AOT compiler or Just in time compiler ...... – user2746466 Jul 18 '19 at 08:52
  • As long as you do production build (--prod), it'll do AOT. – Yakov Fain Jul 19 '19 at 13:27