How to instruct Ajax Minifier to remove console.log from javascript

匆匆过客 提交于 2019-12-21 13:10:22

问题


I have lines in my js files like this

console.log('FunctionName()');

The default Ajax Minifier settings do not remove these lines from the .min.js output.

I noticed in this discussion a conversation about Kill switches.

Looking at the Kill Switch page here. I noticed there is this switch:

/// <summary>
/// remove "debug" statements
/// </summary>
StripDebugStatements = 0x0000000000800000,

I am not using the command line, I am referencing the DLL. This is how I have implemented it.

CodeSettings jsSettings = new CodeSettings()
            {
                KillSwitch = 800000,
            };

and then later the actual minifier method.

string fileMinified = minifier.MinifyJavaScript(fileSource, jsSettings);

How can i remove console.log()?


回答1:


Make you calls to console.Log from methods in "Debug" namespace ( http://ajaxmin.codeplex.com/wikipage?title=Preprocessor )

Sample:

var Debug = {};
Debug.myTrace = function(message){
 console.log(message);
};

///#DEBUG 
someDebugOnlyCode();
///#ENDDEBUG 

All calls to Debug.myTrace will be removed during minification ("debug" namespace), as well as call to someDebugOnlyCode (inside DEBUG/ENDDEBUG comments).



来源:https://stackoverflow.com/questions/9816845/how-to-instruct-ajax-minifier-to-remove-console-log-from-javascript

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