Can gulp watch only for addition/removal of files?

279 Views Asked by At

Example usage:

Task: Using gulp-inject to inject js/**/*.js files into index.html.

Problem: If I watch for changes in the js/**/*.js glob, this would mean that I'm running the inject task each time any of the .js files' content is changed, which is unnecessary, since the paths don't change.

Question: How can I create a watcher that would only watch for addition/removal of the files in the glob?

Thanks!

1

There are 1 best solutions below

0
On

You can give watch a callback function that gets the file object, including the type of event: add - file was added to watch or created change - file was changed unlink - file was deleted see https://www.npmjs.com/package/gulp-watch