簡體   English   中英

Gulp在uglify()未處理的錯誤事件上失敗

[英]Gulp fails on uglify() unhandled error event

我的squish-jquery任務遇到了麻煩。 當它運行時,它會拋出此錯誤:

Starting 'squish-jquery'...

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error
    at new JS_Parse_Error (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:196:18)
    at js_error (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:204:11)
    at croak (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:679:41)
    at token_error (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:683:9)
    at expect_token (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:696:9)
    at expect (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:699:36)
    at function_ (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:959:9)
    at expr_atom (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1188:24)
    at maybe_unary (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1358:19)
    at expr_ops (/Users/shill7/Documents/socialprojects/social-ops-dashboard-angular/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1393:24)

我查了一下,但不幸的是,我找不到與我的錯誤相關的任何內容。 我的設置或Uglify有問​​題嗎? 這是我的gulpfile.js:

    // Load Gulp
var gulp    = require('gulp'),
    gutil   = require('gulp-util');
    plugins = require('gulp-load-plugins')();

var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var ignore = require('gulp-ignore');

// Start Watching: Run "gulp"
gulp.task('default', ['watch']);

// Minify jQuery Plugins: Run manually with: "gulp squish-jquery"
gulp.task('squish-jquery', function() {
  return gulp.src(['src/bower_components/**/*.js', '!src/bower_components/**/*.min.js'])
    .pipe(ignore.exclude([ "**/*.map" ]))
    .pipe(plugins.uglify())
    .pipe(plugins.concat('jquery.plugins.min.js'))
    .pipe(gulp.dest('build')).on('error', gutil.log);
});

// Minify Custom JS: Run manually with: "gulp build-js"
gulp.task('build-js', function() {
  return gulp.src(['src/js/**/*.js', 'src/js/components-controllers/*.js'])
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('jshint-stylish'))
    .pipe(plugins.uglify())
    .pipe(plugins.concat('scripts.min.js'))
    .pipe(gulp.dest('build'));
});

// Less to CSS: Run manually with: "gulp build-css"
gulp.task('build-css', function() {
    return gulp.src('src/less/all.less')
        .pipe(plugins.plumber())
        .pipe(plugins.less())
        .on('error', function (err) {
            gutil.log(err);
            this.emit('end');
        })
        .pipe(plugins.autoprefixer(
            {
                browsers: [
                    '> 1%',
                    'last 2 versions',
                    'firefox >= 4',
                    'safari 7',
                    'safari 8',
                    'IE 8',
                    'IE 9',
                    'IE 10',
                    'IE 11'
                ],
                cascade: false
            }
        ))
        .pipe(plugins.cssmin())
        .pipe(gulp.dest('build')).on('error', gutil.log);
});

//Image minification
gulp.task('imagemin', function() {
    return gulp.src('src/images/*')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngquant()]
        }))
        .pipe(gulp.dest('build/images'));
});

// Default task
gulp.task('watch', function() {
    gulp.watch('src/bower_components/**/*.js', ['squish-jquery']);
    gulp.watch('src/js/**.js', ['build-js']);
    gulp.watch('src/images/*', ['imagemin']);
    gulp.watch('src/less/**/*.less', ['build-css']);
});

根據我上面的評論,您應該打開uglify插件的錯誤日志記錄,以確定錯誤發生在哪里:

//....
.pipe(uglify())
.on('error', function(){
  //do whatever here
})
//....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM