Gulp.watch()会返回咱们熟知的watcher。咱们能够利用watcher来监听额外的事件或者向watch中添加文件。html
例如,在执行一系列任务和调用一个函数时,你就能够在返回的watcher中添加监听change事件:gulp
var watcher = gulp.watch('templates/*.tmpl.html', ['build']); watcher.on('change', function (event) { console.log('Event type: ' + event.type); // added, changed, or deleted console.log('Event path: ' + event.path); // The path of the modified file });
除了change事件,还能够监听不少其余的事件:函数
Watcher对象也包含了一些能够调用的方法:ui