是否可以将 TypeScript 编译为缩小代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12682268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:46:11  来源:igfitidea点击:

Is it possible to compile TypeScript into minified code?

typescript

提问by LordZardeck

Is there an option to compile TypeScript code's output as minified? Or are we left to deal with that in a separate process? And does obfuscation affect the answer?

是否可以选择将 TypeScript 代码的输出编译为缩小版?还是让我们在一个单独的流程中处理这个问题?混淆会影响答案吗?

采纳答案by mohamed hegazy

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.

TypeScript 编译器不支持生成缩小或混淆代码。您将需要针对编译器的 JavaScript 输出使用另一个工具。

There's an open feature request: microsoft/TypeScript#8

有一个开放的功能请求:microsoft/TypeScript#8

回答by Sagi

I am the author of typescript-closure-compiler.
Basically it is a tool that emits files that are compatible with google closure compiler, which is probably the best minifier/optimizer/obfuscator out there.
I've also created a playgroundthat can show you the generated output.
You can take a look at an example projectwhich uses this tool.
The minification process is done using gulp.

我是typescript-closure-compiler 的作者
基本上它是一个发出与谷歌闭包编译器兼容的文件的工具,这可能是最好的缩小器/优化器/混淆器。
我还创建了一个可以向您展示生成的输出的游乐场
您可以查看使用此工具的示例项目
缩小过程是使用 gulp 完成的。