Search code examples
typescriptangularsystemjs

get TypeScript to generate named registers rather than anonymous registers


I'm using Angular2 with SystemJS. I ran across a few issues which came down to the fact that TypeScript compiler generates anonymous registers rather than named registers:

...
System.register([], [...deps...], ...); //Generated by TypeScript compiler
System.register('myModule', [...deps...], ...); //How to do this?
...

This is for purpose of bundling. I like to do what Angular2 does already for my own components. Put multiple System.register calls in one minified file then import the root component.

How to accomplish this?


Solution

  • You need to set the "outFile" attribute in the TypeScript compiler configuration (i.e. tsconfig.json) with a file name.

    In this case, all modules will be compiled into a single file (the specified one) and they will be named modules not anonymous ones.