有没有可能把 TypeScript 编译成小型代码?

是否有一个选项来编译 TypeScript 代码的输出作为缩小?还是让我们单独处理这个问题?模糊不清会影响答案吗?

67746 次浏览

The TypeScript compiler does not support the generation of minifies or obfuscated code. you will need to use another tool against the JavaScript output of the compiler.

有一个开放特性请求: Microsoft/TypeScript # 8

我是 typescript-closure-compiler的作者。
基本上,它是一个工具,发出的文件是与谷歌闭包编译器兼容,这可能是最好的小型化/优化器/模糊处理器。
我还创建了一个 游乐场,它可以显示生成的输出。
您可以看一下使用此工具的 项目示例。
The minification process is done using gulp.

缩小的行业标准是 esbuild。(链接)

编译成 Javascript 后调用 esbuild

esbuild your_file.js --minify --outfile=your_file.min.js

一个例子:

tsc --strict --lib DOM,DOM.Iterable,ES6 --target ES6 your_file.ts && esbuild your_file.js --minify --outfile=your_file.min.js