0

I am using gulp-uglify to compress & minify the javascript file. It runs perfectly. But the problem is, when there is javascript error in the file, it will fail to build and it doesn't show any sign of error informing the process is fail.

gulp.task('compressjs', function() {
    gulp.src(['public/**/*.js','!public/**/*.min.js'])
    .pipe(sourcemaps.init())
    .pipe(concat('all.js'))
    .pipe(wrap('(function(){"use strict"; <%= contents %>\n})();'))
    .pipe(uglify())
    .pipe(rename({
        extname: '.min.js'
    }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('public'));
});

How can I get the error message when it fail to minify javascript file?

user1995781
  • 19,085
  • 45
  • 135
  • 236

1 Answers1

0

below is example of how to use .on('error',...

var gulp, browserify, stringify, sass, concat, uglify, source, buffer;

gulp = require('gulp');
browserify = require('gulp-browserify');
stringify = require('stringify');
sass = require('gulp-sass');
concat = require('gulp-concat');
uglify = require('gulp-uglify');

function handleError(err) {
    console.log(err.toString());
}

gulp.task('browserify', function () {
    return gulp.src('./src/js/**/*.js', { read: false })
               .pipe(browserify({
                   transform: [stringify({
                       extensions: ['.html'],
                       minify: true
                   })]
               }))
               .on('error', handleError)
               .pipe(concat('main.js'))
               .pipe(gulp.dest('./bin/js'));
});
harishr
  • 17,807
  • 9
  • 78
  • 125