Search code examples
gulpgulp-watch

Get gulp watch modified file path


I am using gulp-watch to monitor for file changes.

watch('public/**/*.js', function () {
    runSequence('compressjs');
});

How can I capture the path of modified file for custom processing use later on?


Solution

  • You can try it like this:

    watch('public/**/*.js').on('change', function (file) {
        runSequence('compressjs');
    });
    

    Now the file is available within the scope of the function. You can for example use file.path to get the path of the file that was changed.

    Edit: The above solution only works with gulp.watch, but looking at the code for the gulp-watch plugin, I think the following should work for the plugin:

    watch('public/**/*.js', function (file) {
        runSequence('compressjs');
    });