带有通知的 Gulp-sass 错误 [英] Gulp-sass error with notify
本文介绍了带有通知的 Gulp-sass 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有办法让通知显示有关 gulp-sass 错误的消息.最好是显示在控制台中的实际消息.
I wondered if there is a way to have notify display a message on gulp-sass error. preferably the actual message that is displayed in the console.
我的 gulp 任务如下所示:
my gulp task looks like this:
gulp.task('styles', function() {
return gulp.src('src/scss/style.scss')
.pipe(sass({ style: 'compressed', errLogToConsole: true }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest(''))
.pipe(livereload(server))
.pipe(notify({ message: 'Styles task complete' }));
});
我想通过管道将通知传递给某种错误回调.
I'd like to pipe the notify to some kind of error callback.
任何帮助表示赞赏.
推荐答案
经过自己的努力,我发现这行得通:
After struggling with this myself I found that this worked:
gulp.task('styles', function() {
return gulp.src('src/scss/style.scss')
.pipe(sass({
style: 'compressed',
errLogToConsole: false,
onError: function(err) {
return notify().write(err);
}
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest(''))
.pipe(livereload(server))
.pipe(notify({ message: 'Styles task complete' }));
});
您需要使用 gulp-sass 提供的 onError
选项来捕获错误.
You need to catch the error using the onError
option that gulp-sass provides.
希望有帮助!
这篇关于带有通知的 Gulp-sass 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文