As the question states. I know gulp-uglify can uglify with a simple:
gulp.src('filename')
.pipe(uglify())
Is there a way to tell it to strip out console.log statements too?
Yes there is! As gulp-uglifyjs documentation mentions you can pass extra options ( gulp-uglifyjs documentation):
uglify([filename], [options])
All available options can be found on the compressor UglifyJS documentation page. From that 'drop_console: true' should help:
uglify([filename], {
compress: {
drop_console: true
}
})
Much better still: you can use the specialized gulp plugin: gulp-strip-debug. It doesn't only strip out console statements, but also alerts and debugger statements.
Strip console, alert, and debugger statements from JavaScript code with strip-debug
install it using:
npm install --save-dev gulp-strip-debug
and use it like:
var gulp = require('gulp');
var stripDebug = require('gulp-strip-debug');
gulp.task('default', function () {
return gulp.src('src/app.js')
.pipe(stripDebug())
.pipe(gulp.dest('dist'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With