• Hmm, it's a thought. I wonder whether minification could be modified to do what you want though. For instance:

    var DBG = false;
    
    if (DBG) console.log("Debug");
    console.log("Foo");
    

    That actually works fine when minified - it goes down to:

    var DBG=!1;console.log("Foo");
    

    However when in a function, it doesn't work properly (because it thinks that the state of DBG might get changed). Object.freeze doesn't seem to work either. You could do:

    (function() {
      var DBG = false;
    
      function foo() {
        if (DBG) console.log("Debug");
        console.log("Foo");
      }
    
      setTimeout(foo,1000);
    })();
    

    And that minifies down really nicely:

    (function(){setTimeout(function(){consol­e.log("Foo")},1E3)})();
    
About

Avatar for Gordon @Gordon started