2

My background

I use TypeScript and Visual Studio to compile awesome strongly typed syntax into slutty JavaScript. I've configured the project and Visual Studio to do the following:

  1. Combine multiple compiled JavaScript files to a single JavaScript file
  2. Generate a source map file

In my generated JSON object that is found in the generated source map file, I can see in his "names" property a whole lot of references to method names and other stuff that occurs in my original TypeScript .ts files. These "symbol names" (as the specification proposal like to call them) also occurs in my final .js file.

The one problem that I seek to solve is to minimize the generated JavaScript file, yet keep all the cool functionality a source map file provides.

The question

Since I haven't figured out how to make Visual Studio himself minimize the JavaScript file and then generate the awesome source map file (how?), what would happen if I use another tool to do the minification; would the untouched source map file still work as intended?

My worries is largely because I assume that the tool will provide new symbol names in the minified file. Of course, the most preferred solution for me would be to have Visual Studio do the minification himself before generating a source map file.

Martin Andersson
  • 18,072
  • 9
  • 87
  • 115
  • 2
    [UglifyJS2](https://github.com/mishoo/UglifyJS2#composed-source-map) has an option (`--in-source-map`) to specify an input source file, this is then used to generate the new source file for the minified version. I currently don't have the time to explain how to use. – t.niese Jan 06 '14 at 13:16
  • Wouldn't doing so - generate a **new** source map file - lose my bounding to the original `.ts`files? – Martin Andersson Jan 06 '14 at 13:17
  • 2
    You need to tell `UglifyJS2` the file you want to minify and its current source map. It will then minify and generate a new source map so that there is a mapping from minified to `.ts` – t.niese Jan 06 '14 at 13:20
  • Oh cool. That sounds really awesome! I'll google my way out a here and figure out how-to. I'll perhaps document my steps in a self-posted answer. But if you get time off, please do try to post something that I can accept as an answer. Appreciate your help. – Martin Andersson Jan 06 '14 at 13:22
  • 1
    Oh how I would love to hear the rationale behind the down voter. – Martin Andersson Jan 06 '14 at 14:32

1 Answers1

1

One part of the answer is that the latest version of the TypeScript compiler, as of now, does not support minification.

Martin Andersson
  • 18,072
  • 9
  • 87
  • 115
  • Has it ever supported minification? Seems like this was an external feature. The link you referred says this: "currently doesn't support minification". The official stance regarding minification (and stripping of comments) is to use an external tool. – oligofren Sep 14 '15 at 15:34