简体   繁体   English

使用gulp-ruby-sass 1.0.0-alpha,gulp-notify和浏览器同步进行错误处理

[英]Error handling with gulp-ruby-sass 1.0.0-alpha, gulp-notify, and browser-sync

I've been using `gulp-ruby-sass@1.0.0-alpha' because < 1.0 doesn't play well with Sass >= 3.4 According to the documentation: 我一直在使用`gulp-ruby-sass@1.0.0-alpha',因为根据文档,<1.0在Sass> = 3.4上不能很好地发挥作用:

gulp-ruby-sass throws errors like a gulp plugin, but streams the erroring files so you can see the errors in your browser. gulp-ruby-sass会像gulp插件一样引发错误,但会流式传输错误文件,以便您可以在浏览器中查看错误。

I use gulp-notify to handle errors with this code that gives me a popup notification that lets me know that something went wrong. 我使用gulp-notify处理此代码中的错误,该代码为我提供了一个弹出通知,让我知道出了点问题。

.on('error', notify.onError({
    title: 'Error!',
    message: '<%= error.message %>',
    sound: 'Beep'
}))

This works as-is for my other tasks (in my 'scripts' task I need to specify the gulp-jshint fail reporter). 这对于其他任务保持原样(在我的“脚本”任务中,我需要指定gulp-jshint失败报告程序)。 But in my 'styles' task the error message is being streamed to the console and the browser but not to a popup notification. 但是在我的“样式”任务中,错误消息被流式传输到控制台和浏览器,而不是流式传输通知。

It's workable as is, but when using browser-sync for css style injection, the error message can be missed. 它可以按原样使用,但是当使用浏览器同步进行CSS样式注入时,可能会丢失错误消息。 Sometimes I'm not working at the top of the document where it renders the error message. 有时,我不在显示错误消息的文档顶部工作。

Ideally, I would like to receive a notification that can prompt me to check for errors. 理想情况下,我希望收到一条提示,提示我检查错误。 Does anyone know why I can't create a message with gulp-notify? 有谁知道为什么我不能用gulp-notify创建消息?

The solution I found was to wrap notify.onError in an anonymous function and append this.emit('end') : 我发现的解决方案是将notify.onError包装在一个匿名函数中,并附加this.emit('end')

.on('error', function(err) {
    notify.onError({
        title: 'Error!',
        message: '<%= error.message %>',
        sound: 'Beep'
    })(err);
    this.emit('end');
})

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

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