plugin-typescript icon indicating copy to clipboard operation
plugin-typescript copied to clipboard

Angular AoT Compilation Support

Open laurentgoudet opened this issue 8 years ago • 4 comments

First, thanks for your awesome work on that plugin! I was wondering how/if support for Angular's AoT Compiler could be added.

As describe at @angular/compiler-cli:

This CLI is intended for demos, prototyping, or for users with simple build systems that run bare tsc.

Users with a build system should expect an Angular 2 template plugin. Such a plugin would be based on the index.ts in this directory, but should share the TypeScript compiler instance with the one already used in the plugin for TypeScript typechecking and emit.

Its high level design being:

At a high level, this program

  • collects static metadata about the sources using the tsc-wrapped package in angular2
  • uses the OfflineCompiler from angular2/src/compiler/compiler to codegen additional .ts files
  • these .ts files are written to the genDir path, then compiled together with the application.

While I guess the TypeScript version could be overridden by tsc-wrapper, the full Angular compilation process is more complex and may be too-specialized for the purpose of that plugin. However, creating another plugin-typescript-angular would mean duplicating efforts.

laurentgoudet avatar Sep 12 '16 09:09 laurentgoudet

I don't think everyone who uses typescript with SystemJS wants to have a dependency on angular.

However, creating another plugin-typescript-angular would mean duplicating efforts.

Not necessarily - this plugin itself is less than 200 lines of code, everything else seems perfectly reusable.

fictitious avatar Sep 13 '16 02:09 fictitious

I'm still skeptical of tsc-wrapped. I do not like the idea of Angular extending the language independently. I was using TypeScript before Angular 2 and I will keep using it. Of course it is possible that they will not deviate too much from TypeScript but it is tough to say at this point. I fear @Script lives on...

aluanhaddad avatar Sep 23 '16 00:09 aluanhaddad

Possibly this could be done by exposing the TypeScript CompilerHost globally so that it could be shared with a separate AoT plugin? It's not really something I would want to take on but if there is something I can do to facilitate it then I am happy to make changes.

frankwallis avatar Oct 02 '16 17:10 frankwallis

plugin-typescript now exposes a global variable tsfactory which is a Promise<FactoryOutput> and would enable other plugins to access the CompilerHost used by plugin-typescript (along with the Resolver, TypeChecker and Transpiler). This makes it possible for an AOT compiler plugin to uses these objects to compile files.

frankwallis avatar Nov 03 '16 23:11 frankwallis