【问题标题】:How to instruct Ajax Minifier to remove console.log from javascript如何指示 Ajax Minifier 从 javascript 中删除 console.log
【发布时间】:2012-03-22 05:18:52
【问题描述】:

我的 js 文件中有这样的行

console.log('FunctionName()');

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

我在这次讨论中注意到conversation about Kill switches

查看终止开关page here。我注意到有这个开关:

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

我没有使用命令行,我引用的是 DLL。我就是这样实现的。

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

然后是实际的缩小器方法。

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

如何删除 console.log()?

【问题讨论】:

    标签: minify microsoft-ajax-minifier


    【解决方案1】:

    让您从“Debug”命名空间 (http://ajaxmin.codeplex.com/wikipage?title=Preprocessor) 中的方法调用 console.Log

    示例:

    var Debug = {};
    Debug.myTrace = function(message){
     console.log(message);
    };
    
    ///#DEBUG 
    someDebugOnlyCode();
    ///#ENDDEBUG 
    

    所有对 Debug.myTrace 的调用都将在缩小期间被删除(“debug”命名空间),以及对 someDebugOnlyCode 的调用(在 DEBUG/ENDDEBUG cmets 内)。

    【讨论】:

    • 还是这样吗?提供的链接不再存在,我的日志仍在显示,遵循这种方法。
    猜你喜欢
    • 2019-06-12
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多