如何指示Ajax Minifier从JavaScript删除console.log [英] How to instruct Ajax Minifier to remove console.log from javascript

查看:82
本文介绍了如何指示Ajax Minifier从JavaScript删除console.log的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的js文件中有这样的行

I have lines in my js files like this

console.log('FunctionName()');

默认的Ajax Minifier设置不会从.min.js输出中删除这些行.

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,

我没有使用命令行,而是引用了DLL.这就是我的实现方式.

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);

如何删除console.log()?

How can i remove console.log()?

推荐答案

调用控制台.从调试"命名空间中的方法登录(

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

示例:

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

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

在最小化期间​​(调试"名称空间)以及对someDebugOnlyCode的调用(在DEBUG/ENDDEBUG注释内部)将删除对Debug.myTrace的所有调用.

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

这篇关于如何指示Ajax Minifier从JavaScript删除console.log的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆