Exclude debug JavaScript code during minification

后端 未结 11 1999
庸人自扰
庸人自扰 2020-11-28 07:16

I\'m looking into different ways to minify my JavaScript code including the regular JSMin, Packer, and YUI solutions. I\'m really interested in the new Google Closure Compil

11条回答
  •  离开以前
    2020-11-28 07:41

    If you use the Closure Compiler in Advanced mode, you can do something like:

    if (DEBUG) console.log = function() {}
    

    Then the compiler will remove all your console.log calls. Of course you need to --define the variable DEBUG in the command line.

    However, this is only for Advanced mode. If you are using Simple mode, you'll need to run a preprocessor on your source file.

    Why not consider the Dojo Toolkit? It has built-in comment-based pragma's to include/exclude sections of code based on a build. Plus, it is compatible with the Closure Compiler in Advanced mode (see link below)!

    http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t

提交回复
热议问题