Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gulp-uglify strip out console.log statements?

Tags:

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?

like image 675
Rolando Avatar asked Mar 09 '15 13:03

Rolando


2 Answers

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
    }
})
like image 115
Fill Avatar answered Sep 18 '22 00:09

Fill


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'));
});
like image 34
Elger van Boxtel Avatar answered Sep 21 '22 00:09

Elger van Boxtel