Support minification


Script# supports minification, and TypeScript should too. (This is better than using third party minifiers because compiler-generated minified code is more reliable.)
Closed Jul 28 at 11:17 PM by jonturner
As part of our move to GitHub, we're closing our CodePlex suggestions and asking that people move them to the GitHub issue tracker for further discussion. Some feature requests may already be active on GitHub, so please make sure to look for an existing issue before filing a new one.

You can find our GitHub issue tracker here:


MgSam wrote Oct 11, 2012 at 1:54 PM

It should support not just simple minification, but code optimization as well (function inlining, variable eliding, etc.) The type information the compiler has should make it possible for more aggressive optimizations than an external minifier.

slinnarsson wrote Oct 11, 2012 at 10:00 PM

It should also support bundling and automatically calculate a partial ordering of the graph (DAG) that is formed by the ///<reference... directives. This way you don't have to keep track of which file should come first in the bundle.

admiristrator wrote Oct 12, 2012 at 1:33 AM

Yes, both advanced optimizations, minification, and bundling are really critical. Advanced optimizations, at least, require the TypeScript to be involved, both for getting all the juice out AND for source mapping.

I know you know. I know you're probably on it. You guys are great.

majo44 wrote Oct 12, 2012 at 9:26 AM

+1. But remember about preserve the "exported" names (eg. angularjs) !!

JimAllanson wrote Oct 15, 2012 at 1:41 PM

If the compiler were able to produce Google Closure flavour JSDoc (see: https://developers.google.com/closure/compiler/docs/js-for-compiler), we could use Closure Compiler for minification & optimizations.

Gleno wrote Oct 20, 2012 at 12:12 PM

I disagree, I think the produced JS should be human readable to allow debugging.

slashdotdash wrote Oct 24, 2012 at 11:42 AM

@Gleno if the minification works with the existing Source Maps support then debugging would be fine since you're using the TypeScript source.

JimAllanson wrote Oct 29, 2012 at 4:29 PM

@Gleno It would be unusual to say the least if minification were the ONLY supported output. Generally a compile time switch is provided to determine the level of minification.

aaronlev wrote Dec 13, 2012 at 11:10 PM

Removal of dead code is a big one here. For example, if I write several implementations of a class and choose which I want at compile time, there are more optimizations to be had. Depending on what each implementation calls more code can be stripped out. The compiler sees all the dependencies it can strip out all the unused code no matter where it is.

JimAllanson wrote Jan 18, 2013 at 1:34 PM

Michael Bolin has created a prototype that outputs Google Closure type annotations from TypeScript files. (http://blog.bolinfest.com/2013/01/generating-google-closure-javascript.html)

This should allow you to use the output with the advanced optimizations mode of Closure compiler, enabling much more effective minification, including dead code removal.

Paul0515 wrote Feb 7, 2013 at 12:44 PM

I'd say minimizing straight from typescript compiler looks interesting but not as topprio. IMHO the focus should be on getting the language constructs at optimized level ... en to ensure that tooling support is optimal. Every inch progress in terms of efficiency in the workflow when programming is worth a million to me. I think every dev would agree on that!

Minimizing and bundling is already solved in my project, would be nice if it could be optimized, but please ...

Paul0515 wrote Feb 7, 2013 at 12:52 PM

I like it, for version 2.0 or so. Please focus on getting the language lean and efficient including an optimal match with tooling. Every inch of progress on that area realy helps the every day routines of each developer.

Minification and so on is already solved in everyones workflow I'd guess.

Optimizations achievable (because it's done by the compiler) really are the cherrys on the cake that we'd all appreciate as well, but a cherry without the cake???

ps. I thought I'd comment here as counter weight to the huge vote count this topic received!

LukeH wrote Feb 19, 2013 at 5:37 PM

As others have noted here, minification is something we definitely want to add longer term, but we are currently focusing on core language and tools scenarios that can't be provided by other build chain additions. There are great existing minifiers which can be chained with TypeScript in a build process, and until we build something more directly integrated, these are a great option for TypeScript.

mindplay wrote Sep 25, 2013 at 5:33 PM

I see this as a problem to be solved by the IDE, not by the compiler, for all the reasons explained here.