gulp.watch 监控不到文件的增加是为什么

2025-05-01 07:33:08
推荐回答(3个)
回答1:

gulp.watch 监控不到文件的增加是为什么?

  • 下面是我的代码:

  • gulp.watch([config.src + '/**/**'], function(event) {

  •     console.log('File ' + event.path + ' was ' + event.type);      

  • });

因为config.src = './app'; 去掉 './'就可以监控到了。

回答2:

嗯。您说得对。gulp.watch 不监听文件的新建和删除。

所以一个更好一点的方案是用一个插件 gulp-watch。

npm install gulp-watch

详情请移步这里:

https://www.npmjs.com/package/gulp-watch

https://github.com/floatdrop/gulp-watch

回答3:

我也找了很久, 监听路径格式 "./aaaa/bbb" 这种头部带 "./" 格式 在 添加文件 和 删除文件的时候不会触发监听
只要把 "./" 去掉(str.substr(2)) 截掉就可以触发监听了