問題描述
我正在使用 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!