93
Vote

Support minification

description

Script# supports minification, and TypeScript should too. (This is better than using third party minifiers because compiler-generated minified code is more reliable.)

comments

MgSam wrote Oct 11, 2012 at 12: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 9: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 12: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 8:26 AM

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

JimAllanson wrote Oct 15, 2012 at 12: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 11:12 AM

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

slashdotdash wrote Oct 24, 2012 at 10: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 3: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 10: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 12: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 11:44 AM

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 11:52 AM

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 4: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 4:33 PM

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