How do I prevent gulp-notify from breaking gulp-watch in Windows?(如何防止 gulp-notify 在 Windows 中破坏 gulp-watch?)
问题描述
我正在使用 gulp-notify 插件.这是我如何在 gulpfile.js 中实现它的一个例子(你可以看到我也在使用 gutil 和 livereload.我不知道它们是否发挥了任何作用,但如果它们发挥作用,请告诉我.)
I am using the gulp-notify plugin. This is an example of how I'm implementing it in a gulpfile.js ( You can see I'm using gutil and livereload as well. I don't know if they play any factors, but let me know if they do.)
gulp.task('js', function() {
return gulp.src('./dev/scripts/*.coffee')
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe( gulp.dest('./build/js'))
.pipe(notify('Coffeescript compile successful'))
.pipe(livereload(server));
});
此插件适用于 OS X 和 Linux.在没有通知功能的 Windows 上,它会返回错误并破坏 gulp-watch 插件.这是我如何设置 gulp-watch 的示例:
This plugin works on OS X and Linux. On Windows, which doesn't have a notification feature, it returns an error and breaks the gulp-watch plugin. This is an example of how I have gulp-watch setup:
gulp.task('watch', function () {
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
gulp.watch('./dev/scripts/*.coffee',['js']);
});
});
因此,我在文档中阅读了 gulp-pipe 插件可以帮助我在 Windows 上不破坏 gulp-watch,但我找不到如何在这样的设置中使用它的示例.
So, I read in the documentation the gulp-pipe plugin can help me not break gulp-watch when on Windows, but I can't find an example of how I could use it in a setup like this.
推荐答案
你可以使用 gulp-if
插件结合os
节点模块来确定您是否在 Windows 上,然后排除 gulp-notify
,如下所示:
You can use the gulp-if
plugin in combination with the os
node module to determine if you are on Windows, then exclude gulp-notify
, like so:
var _if = require('gulp-if');
//...
// From http://stackoverflow.com/questions/8683895/variable-to-detect-operating-system-in-node-scripts
var isWindows = /^win/.test(require('os').platform());
//...
// use like so:
.pipe(_if(!isWindows, notify('Coffeescript compile successful')))
这篇关于如何防止 gulp-notify 在 Windows 中破坏 gulp-watch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何防止 gulp-notify 在 Windows 中破坏 gulp-watch?


- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07