1

I have a js file that contains lots of debug statements. I am looking for a script or compiler that will skip these debug statements, and can provide a production version.

function init(){
  console.log('initing the lib');
  ...
  .. some code here ..
  ...
  console.log('init over');
}

I need to have a production version that has none of these console.log's. This will allow for writing a debug version that can be used to see where exactly the error is occuring.

Amit
  • 3,952
  • 7
  • 46
  • 80

1 Answers1

1

Maybe googles closure compile can help you out?

If you're worried about the console.log (seems that's what you mean by 'debug statements'), it may be an idea to override it in production:

var isProduction = true; //or false
if (isProduction){
 window.console = {log: function(){return true;}};
}
KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • Does it have something that lets you mark a section as debug code it should omit? – T.J. Crowder Apr 30 '12 at 08:20
  • In the faq (http://code.google.com/p/closure-compiler/wiki/FAQ), this is stated: *Closure Compiler will remove code that isn't used or exported.* Maybe this is applicable: https://developers.google.com/closure/compiler/docs/api-tutorial3?#removal – KooiInc Apr 30 '12 at 08:29
  • You will maybe want to mark this variable as constant: `/** @const */ var DEBUG = false;` – Niko May 01 '12 at 07:56