重命名或删除文件夹后Gulp崩溃

时间:2018-05-27 10:08:36

标签: javascript gulp gulp-watch

更改文件夹名称或删除文件夹后,Gulp崩溃。这是每个人都遇到的常见问题吗?

// Task to copy images to dist.
gulp.task('copy-images', function() {
  return gulp.src([
    'images/*.{jpg,png,gif}',
    'images/**/*.{jpg,png,gif}',
    'node_modules/jquery-ui-bundle/images/*',
  ])
  .pipe(gulp.dest('dist/images/'))
})

// Task to watch.
gulp.task('watch', function () {
  // Watch all the fonts files recursively.
  gulp.watch([
    'images/**'
  ], [
    'copy-images'
  ])
})

因此,当我添加新文件夹logos1时,我得到:

[10:58:31] Starting 'watch'...
[10:58:31] Finished 'watch' after 13 ms
[11:02:10] Starting 'copy-images'...
[11:02:10] Finished 'copy-images' after 58 ms

这是我的期望。但是,如果我删除 logos1添加新文件夹logos2,gulp会崩溃:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: watch /var/www/html/xxx8/images/logos1 ENOENT
    at _errnoException (util.js:1022:11)
    at FSWatcher.start (fs.js:1382:19)
    at Object.fs.watch (fs.js:1408:11)

抱怨我删除了logos1

有什么想法吗?任何解决方案?

1 个答案:

答案 0 :(得分:0)

我使用这两个包来解决问题:

代码:

gulp.task('watch', function () {
  watch([
      'images/**',
      'images/**/*.{jpg,png,gif}'
    ], batch(function (events, done) {
      gulp.start('copy-images', done)
  }))
  watch([
      'fonts/**',
      'fonts/**/*.{eot,svg,ttf,woff,woff2}'
    ], batch(function (events, done) {
      gulp.start('copy-fonts', done)
  }))
})

不再崩溃!

相关问题