Gulp js 错误通知未显示错误源



一切都已设置并努力连接和编译我的样式和脚本。当错误发生gulp-notify并且gulp-plumber将错误作为 mac 通知并在终端中抛出时,gulp 不会停止运行 - 这是一个很好的:)

但是,我发现终端中抛出的脚本错误始终是编译文件script-dist.js而不是实际连接的源文件的问题。

错误

gulp-notify: [JS Error] _PATH_/js/script-dist.js: Unexpected token keyword «var», expected punc «{»
Error in plugin 'gulp-uglify'
Message:
    _PATH_/js/script-dist.js: Unexpected token keyword «var», expected punc «{»
Details:
    fileName: _PATH_/js/script-dist.js
    lineNumber: 3

请注意,这并没有告诉我实际错误来自哪里(它应该说它在_modal.js,我故意在其中创建错误的级联文件之一。

古尔普文件.js

var gulp = require('gulp'); 
// --------------------------------------------------------------
// Plugins
// ---------------------------------------------------------------
var concat = require('gulp-concat');
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var include = require('gulp-include');
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');
var watch = require('gulp-watch');
var livereload = require('gulp-livereload');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
// --------------------------------------------------------------
// JS
// ---------------------------------------------------------------
gulp.task('scripts', function() {
    return gulp.src(['./js/script.js'])
        .pipe(include())
        .pipe(plumber({errorHandler: errorScripts}))
        .pipe(concat('script-dist.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./js/'))
        .pipe(livereload());
});
// --------------------------------------------------------------
// Styles
// ---------------------------------------------------------------
gulp.task("styles", function(){
    return gulp.src("./ui/scss/styles.scss")
        .pipe(include())
        .pipe(plumber({errorHandler: errorStyles}))
        .pipe(sass({style: "compressed", noCache: true}))
        .pipe(minifycss())
        .pipe(gulp.dest("./ui/css/"))
        .pipe(livereload());
});

// --------------------------------------------------------------
// Errors
// ---------------------------------------------------------------
// Styles
function errorStyles(error){
    notify.onError({title: "Sass Error", message: "", sound: "Sosumi"})(error); //Error Notification
    console.log(error.toString()); // Prints Error to Console
    this.emit("end");
};
// Scripts
function errorScripts(error){
    notify.onError({title: "JS Error", message: "", sound: "Sosumi"})(error); //Error Notification
    console.log(error.toString()); // Prints Error to Console
    this.emit("end");
};
// --------------------------------------------------------------
// Watch & Reload
// ---------------------------------------------------------------
gulp.task('watch', function() {   
    gulp.watch('./ui/scss/*.scss', ['styles']);
    gulp.watch(['./js/*.js', '!./js/script-dist.js'], ['scripts']);
});
gulp.task('default', ['styles', 'watch']);
gulp.task('default', ['scripts', 'watch']);
livereload.listen();
task("styles", function(){
        return gulp.src("./ui/scss/styles.scss")
            .pipe(include())
            .pipe(plumber({errorHandler: errorStyles}))
            .pipe(sass({style: "compressed", noCache: true}))
            .pipe(minifycss())
            .pipe(gulp.dest("./ui/css/"))
            .pipe(livereload());
    });

    // --------------------------------------------------------------
    // Errors
    // ---------------------------------------------------------------
    // Styles
    function errorStyles(error){
        notify.onError({title: "Sass Error", message: "", sound: "Sosumi"})(error); //Error Notification
        console.log(error.toString()); // Prints Error to Console
        this.emit("end");
    };
    // Scripts
    function errorScripts(error){
        notify.onError({title: "JS Error", message: "", sound: "Sosumi"})(error); //Error Notification
        console.log(error.toString()); // Prints Error to Console
        this.emit("end");
    };
    // --------------------------------------------------------------
    // Watch & Reload
    // ---------------------------------------------------------------
    gulp.task('watch', function() {   
        gulp.watch('./ui/scss/*.scss', ['styles']);
        gulp.watch(['./js/*.js', '!./js/script-dist.js'], ['scripts']);
    });
    gulp.task('default', ['styles', 'watch']);
    gulp.task('default', ['scripts', 'watch']);
    livereload.listen();

你在传递给uglify之前concat,所以就Uglify而言,那里只有一个文件。例如,您可能希望首先使用linter来传递文件,以确保它们是正确的。

或者,使用源映射,工具可以利用源映射来显示发生错误的原始文件。

相关内容

  • 没有找到相关文章

最新更新