strip-debug

Strip console, alert, and debugger statements from JavaScript code

strip-debug

Strip console, alert, and debugger statements from JavaScript code

Useful for making sure you didn't leave any logging in production code.

Also available as gulp/grunt/broccoli plugins.

$ npm install --save strip-debug
var stripDebug = require('strip-debug');
 
stripDebug('function foo(){console.log("foo");alert("foo");debugger;}').toString();
//=> function foo(){void 0;void 0;} 

Returns the modified Esprima AST which can be used to make additional modifications.

Call .toString() to get the stringified output.

To prevent any side-effects, console.*/alert* is replaced with void 0 instead of being stripped.

Type: string, object

Pass in a string of JavaScript code or a Esprima compatible AST.

$ npm install --global strip-debug
$ strip-debug src/app.js > dist/app.js

or pipe something to it:

echo 'function foo(){console.log("bar")}' | strip-debug
#=> function foo(){} 

MIT © Sindre Sorhus