0 votes
in JAVA by
What is gulp.watch and how to use it?

1 Answer

0 votes
by

As we write code and modify your files, the gulp.watch() method will watch for changes and automatically run our tasks again so we don’t have to run the gulp command each time.

gulp.watch(glob [, opts], tasks) or gulp.watch(glob [, opts, cb])

Example,

gulp.task('watch', function () {

   // Watch .js files

  gulp.watch('src/js/*.js', ['scripts']);

   // Watch .scss files

  gulp.watch('src/scss/*.scss', ['sass']);

});

Here we have defined a task named “watch”, in which we are watching for js files changes and css files changes using gulp.watch. And whenever, there is any change in .js file, then run [scripts] task (which should be already defined in your gulpfile.js) and in case of .scss file changes, run [sass] task.

Related questions

0 votes
asked Feb 15, 2020 in JAVA by rahuljain1
0 votes
0 votes
asked Feb 25, 2020 in JavaScript by miceperry
...