How to remove comments with BundleTransformer YuiJsMinifier

一笑奈何 提交于 2019-12-10 14:44:32

问题


I am using BundleTransformer to minify css and js resources

        <yui>
            <css compressionType="Standard" removeComments="true" lineBreakPosition="-1" />
            <js compressionType="Standard" obfuscateJavascript="true" preserveAllSemicolons="false" disableOptimizations="false" ignoreEval="false" severity="0" lineBreakPosition="-1" encoding="UTF8" threadCulture="en-us" />
        </yui>

As you can see for css it is possible to specify removeComments="true" But in js there is no such option.

I red that YUI js compressor removes comments by default. Yes it is kind of removes, but it is still leave comments like that:

/* NUGET: BEGIN LICENSE TEXT
 *
 *Bla bla bla
 *
 * NUGET: END LICENSE TEXT */

/*!
 * Bla
 * Licensed under http://www.apache.org/licenses/LICENSE-2.0
 */

Looks like there is no way to force YIU js minifier to remove comments.

https://github.com/yui/yuicompressor :

C-style comments starting with /*! are preserved. This is useful with comments containing copyright/license information

Is there anything I can do by using BundleTransformer to completely remove all kind of comments in bundled minified output files? Google page speed strongly recommended me to do that.


回答1:


YUI compressor does not support removing of important comments.

I recommend you to install BundleTransformer.MicrosoftAjax package. Thereafter register MicrosoftAjaxCssMinifier and MicrosoftAjaxJsMinifier as default minifiers, and add to the Web.config file the following configuration settings:

<configuration>
    …
    <bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
        …
        <microsoftAjax>
            <css commentMode="None" />
            <js preserveImportantComments="false" />
        </microsoftAjax>
        …
    </bundleTransformer>
    …
</configuration>


来源:https://stackoverflow.com/questions/20831597/how-to-remove-comments-with-bundletransformer-yuijsminifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!