javascript

Watch files in Gulp

var gulp = require('gulp');

gulp.task('watch', function() {
    gulp.watch('app/scss/*.scss', gulp.series('sass'));
    gulp.watch('app/js/*.js', gulp.series('minifyjs'));
});

You can apply a watch on files using gulp means if there are any changes to those files you can run specific tasks.

In the code snippet, we have created a task named 'watch'. When we run the 'gulp watch' command in the terminal it will start the watch task and continuously watch all .scss files in 'app/scss/' folder and all js files in 'app/js/' folder.

If there is any change in .scss files, it will run the task 'sass' and it will run task 'minifyjs' if there is any change in js files.

Was this helpful?