代码之家  ›  专栏  ›  技术社区  ›  Run

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

  •  0
  • Run  · 技术社区  · 8 年前

    更改或删除文件夹名后,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 回复  |  直到 8 年前
        1
  •  0
  •   Run    8 年前

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

    代码:

    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)
      }))
    })
    

    别再撞车了!