简体   繁体   English

保留条件注释的Minifier?

[英]Minifier that preserves conditional comments?

I tried out the online JS Minifier but it cuts out conditional comments like: 我尝试了在线JS Minifier,但是它删除了以下条件注释:

 var u = navigator.userAgent;var e=/*@cc_on!@*/false;

                           BECOMES

 var u=navigator.userAgent;var e=false;

This would affect the operation of the code, so instead of manually adding the stripped out comments manually, I'm looking for a minifier that intelligently preserves these and any such comments. 这将影响代码的操作,因此,我寻找的是一个可以智能地保留这些注释和任何此类注释的压缩程序,而不是手动手动添加删除的注释。

YUICompressor reportedly does the needful. 据报道,YUICompressor做得很有必要。 Here is an excerpt from a blog: 以下是博客摘录:

... ...
But fret not, it's not as bad as you think. 但是不用担心,它没有您想的那么糟糕。 Unfortunately, JSMin removes conditional compilation comments, but I believe this is due to not having been updated in a while, and not up to speed with modern web development practices. 不幸的是,JSMin删除了条件编译注释,但是我相信这是由于一段时间内没有更新,并且无法与现代Web开发实践保持同步。

Using other tools such as YUI compressor or packer does indeed work fine with conditional compilation. 实际上,使用其他工具(例如YUI压缩器或打包程序)在条件编译中确实可以正常工作。 ... ...

You can read the entire post at http://robertnyman.com/2008/05/26/conditional-compilation-in-javascript/ 您可以在http://robertnyman.com/2008/05/26/conditional-compilation-in-javascript/阅读全文

There's also a .NET port of YUI Compressor which allows you to:- 还有一个YUI Compressor的.NET端口,您可以:-

  • intergrate the minification/file combining into Visual Studio post-build events 将缩小/文件集成到Visual Studio生成后事件中
  • intergrate into a TFS Build (including CI) 集成到TFS Build(包括CI)中
  • if you wish to just use the dll's in your own code (eg. on the fly minification). 如果您只想在自己的代码中使用dll(例如,即时压缩)。

because this is a port of the (original) java version YUI Compressor, which Vinnie and Crescentfresh mention above, it should give you the same results BUT all in the .NET environment -- no need for java. 因为这是(原始)Java版本YUI Compressor的端口,上面的Vinnie和Crescentfresh提到了它,所以它应该在.NET环境中为您提供相同的结果-不需要Java。

HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM