Gulp: 有.on('change') 和没有.on('change') 有区别吗?

Gulp: Is there any difference with .on('change') and without?

有什么区别吗:

gulp.watch("src/sass/**/*.{scss,sass}").on("change", gulp.series("style")); 

gulp.watch("src/sass/**/*.{scss,sass}", gulp.series("style"));

?

看起来效果一样。

还有更多活动可以看,见chokidar watch events

在我的测试中,如果我使用

gulp.watch("src/sass/**/*.{scss,sass}").on("change", gulp.series("style")); 

如果我添加文件夹或文件或将文件复制到正在监视的预先存在的文件夹中(可能还会删除 - 我只是没有测试一下)。

如果我使用

gulp.watch("src/sass/**/*.{scss,sass}", gulp.series("style"));

以上所有 - 添加和复制事件都会触发任务。显然,不指定监视事件与指定 on("all", ...) 相同。这可能是您想要的,除非您希望在添加、删除或复制文件时与修改现有文件时有不同的行为。这些事件只是给你更细粒度的控制。