Removes all console logging statements from your code.
This plugin is based on the initial work of @ehynds on grunt-remove-logging.
Install this plugin with the command:
npm install gulp-remove-logging
Next, add this line to your gulpfile:
var gulp_remove_logging = require("gulp-remove-logging");
Lastly, add the configuration settings (see below) to your gulpfile.
gulp.task("remove_logging", function() {
return gulp.src("src/javascripts/**/*.js")
.pipe(
gulp_remove_logging({
// Options (optional)
// eg:
// namespace: ['console', 'window.console']
})
)
.pipe(
gulp.dest(
"build/javascripts/"
)
);
});
This plugin can be customized by specifying the following options:
replaceWith
: A value to replace logging statements with. This option defaults to an empty string. If you use fancy statements likeconsole && console.log("foo");
, you may choose to specify areplaceWith
value like0;
so that your scripts don't completely break.namespace
: An array of object names that logging methods are attached to. Defaults to[ 'console', 'window.console' ]
. If you use a custom logger, likeMyApp.logger.log(foo)
, you would set this option to[MyApp.logger]
.methods
: An array of method names to remove. Defaults to all the methods in the Firebug console API. This option is useful if you want to strip out alllog
methods, but keepwarn
for example.verbose
: Boolean value, whether to show count of logging statements removed for each file. Defaults to true. If false, a single summary line is logged to gulp instead.
You can tell this task to keep specific logging statements by adding the comment directive /*RemoveLogging:skip*/
after the statement:
console.log("foo");/*RemoveLogging:skip*/
// or:
console.log("foo")/*RemoveLogging:skip*/;
// whitespace is fine too, whatever floats your boat:
console.log("foo") /* RemoveLogging:skip */;