如何防止 gulp-notify 破坏 Windows 中的 gulp-watch?

2024-05-17

我正在使用吞咽通知 https://www.npmjs.org/package/gulp-notify插入。这是我如何在 gulpfile.js 中实现它的示例(您可以看到我也在使用 gutil 和 livereload。我不知道它们是否发挥任何作用,但请让我知道它们是否发挥作用。)

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 设置的示例:

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,但我找不到如何在这样的设置中使用它的示例。


您可以使用the gulp-if plugin https://www.npmjs.org/package/gulp-if/结合os节点模块 http://nodejs.org/api/os.html#os_os_platform确定您是否使用 Windows,然后排除gulp-notify,像这样:

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')))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何防止 gulp-notify 破坏 Windows 中的 gulp-watch? 的相关文章

随机推荐