Search code examples
gulp

Can gulp-uglify strip out console.log statements?


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?


Solution

  • 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'));
    });