frankwallis / plugin-typescript

TypeScript loader for SystemJS
MIT License
248 stars 47 forks source link

Angular AoT Compilation Support #158

Open laurentgoudet opened 8 years ago

laurentgoudet commented 8 years ago

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.

fictitious commented 8 years ago

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.

aluanhaddad commented 8 years ago

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...

frankwallis commented 8 years ago

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 commented 8 years ago

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.