Google News
logo
Gulp - Interview Questions
How would you set up a Gulp watch task to monitor changes in your files?
To set up a Gulp watch task, first install Gulp and its plugins. Create a gulpfile.js at the root of your project directory. Inside this file, require Gulp and any necessary plugins. Define tasks that perform actions on your files such as compiling or minifying.

For a watch task, use the ‘gulp.watch’ method. This takes two arguments: the path to the files to monitor, and the tasks to run when those files change. For example:
var gulp = require('gulp');
gulp.task('watch', function() {
  gulp.watch('src/js/*.js', ['jshint']);
});​

In this example, Gulp watches for changes in JavaScript files within the ‘src/js’ directory. When a change is detected, it runs the ‘jshint’ task.

Remember to call your watch task from the command line using ‘gulp watch’.
Advertisement