TypeScript Compiling into Single JavaScript File
Posted by robert | Filed under TypeScript
Update: New and better Boilerplate that uses ES6 Modules in TypeScript check it out.
More and more I play around with TypeScript I think it is the best way to do JavaScript development for large and small projects. One thing I’ve noticed is some people are not aware of how easy it is to compile all your referenced .ts files into one JavaScript .js file.
I am not sure if this is not straight forward when using Visual Studio but I am using WebStorm/PhpStorm for my development and using the Command/Terminal Window to manually make my TypeScript commands. To compile all the .tc files into one .js file I use this command:
tsc --out main.js Main.ts
Now I am assuming the Main.ts is your main TypeScript file that has references(///<reference path=’path/to/Class.ts’/>) to other .ts files.
Check out my OOP TypeScript Tutorial as an example how this works.
December 17, 2012 at 8:06 am
Regarding compiling to single file, the default with the Visual Studio plugin is to compile each file into a separate .js file, which it does by specifying all the files in the -out parameter. I think it assumes that you’re typically using it in a ASP.NET project which if you’re using the MVC4 bundler, it will use the unminified files when you’re in debug mode, and use the a combined minified file when you’re in release mode.
If you’re not using it in an ASP.NET MVC4 app, then the single file compile is probably more convenient.