简体   繁体   English

使用Gulp通知和管道工的全局错误消息

[英]Global error message using Gulp Notify & Plumber

Is it possible to create a global OnError function that I can pass a title and the error message to? 是否可以创建一个可以将标题和错误消息传递给的全局OnError函数?

I'm looking to do something like this for all tasks ran with plumber: 我正在为水管工执行的所有任务执行以下操作:

onError = function(error) {
      $.notify.onError({
        title:    'Error',
        subtitle: '<%= file.relative %> did not compile!',
        message:  '<%= error.message %>'   
      })(error);
    };

You can simply save the onError function as a variable: 您可以简单地将onError函数另存为变量:

var onError = notify.onError({
   title:    'Error',
   subtitle: '<%= file.relative %> did not compile!',
   message:  '<%= error.message %>'   
});

And in several different gulp-tasks and plumber-functions: 在几个不同的任务和水管工功能中:

gulp.src('./src/*.ext')
  .pipe(plumber({ errorHandler: onError }))
  .pipe(coffee())
  .pipe(gulp.dest('./dist'));

and somewhere else: 还有其他地方:

gulp.src('./src/*.scss')
  .pipe(plumber({ errorHandler: onError }))
  .pipe(sass())
  .pipe(uglify())
  .pipe(plumber.stop())
  .pipe(gulp.dest('./dist'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM