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



更改文件夹名称或删除文件夹名称后,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

有什么想法吗?有什么解决办法吗?

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

  • 咕噜咕噜
  • 咕噜咕噜

法典:

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

不再崩溃!

最新更新