Global error message using Gulp Notify & Plumber

时光总嘲笑我的痴心妄想 提交于 2019-12-24 02:25:24

问题


Is it possible to create a global OnError function that I can pass a title and the error message to?

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

回答1:


You can simply save the onError function as a variable:

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


来源:https://stackoverflow.com/questions/25782341/global-error-message-using-gulp-notify-plumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!