A new minifying tool for TypeScript

A new minifying tool for TypeScript

I wrote a minifying tool for TypeScript. Welcome to try and report bugs:

minify-ts (https://www.npmjs.com/package/minify-ts)

github: https://github.com/foreverflying/minify-ts

Two weeks ago, I am trying to find a tool that can help me uglify my personal project which was written in TypeScript. After searching for hours, I didn't find any ideal solutions. Traditional uglify tools are for JavaScript, so they cannot get the type info, which can help them figure out how to rename the properties and methods. So they just leave them unchanged.

I decided to write one myself. So I dived deep into the TypeScript compiler APIs and source-map details. I haven't touched this area before, so it took me about a week and a half for researching, design and implementing, but the final effect is worth the time.

Meanwhile, I found another problem: it generates the source map files, but later the tsc compiles the minified code into js and generates another bunch of source maps, and later if I use uglify-js to remove all the spaces and bundle all the files into one, it generates a bundled source-map file, too. In each step, the source map files are mapped to the code files that generate in the previous step, not the original ts file.

I looked for the solutions again, and for the second time, I didn't get a satisfactory result. There are many people having the same problem. For example, a discussion started in 2017, asking TypeScript teams to add a feature to accept source map files as input. What they want is just to get the final source-map files that are mapping to the original code file. After so many years the discussion is still open.

There are several small npm packages aimed to solve this issue, I tried several of them, and the only working one can merge 2 source-map files into 1 each time, not very easy to use and does not support the bundled source-map file. Finally, I decided to solve this problem in minify-ts too.

So the minify-ts provides another feature: merging the source-map files generated from several steps, it can batch process all the source-map files in a folder in a very efficient way, climb up through every source-map chain to the top to collect information, and use the merged result to overwrite the tail one.

After selling the awesome tool, I also need to sell myself:

I am looking for contractor opportunities now, and hope it is 3 months or 1-year contract. I dare to say my programming skill is at the expert level, even for the area I never touched, I can understand it well quickly, and as long as I decide to solve a problem, I can always get the job done.

To view or add a comment, sign in

More articles by Andy Deng

Others also viewed

Explore content categories