How to compile an Angular2 TypeScript application to a single file?

前端 未结 3 693
后悔当初
后悔当初 2021-02-04 13:56

I realize that I can compile my application with tsc my_app.ts --target system and it will generate a SystemJS-wrapped file for each imported module, which is aweso

3条回答
  •  走了就别回头了
    2021-02-04 14:24

    The --outFile option works with the --module option (for AMD and SystemJS) since TypeScript 1.8, so this can be done natively. Here's the changelog. TypeScript also automatically pulls all the dependencies that don't reside in external modules, so it's enough to only compile the main app file.

    If Angular 2 doesn't switch away from SystemJS, the way to bundle your app in a single file should be as simple as compiling it with options like tsc app.ts --target ES5 --module system --experimentalDecorators --moduleResolution node --emitDecoratorMetadata --outFile app.js

    After that it should be possible to bootstrap the application with something like:

    
    
    
    
    

提交回复
热议问题