0

I am trying to upgrade gulp from 3.x to 4.x When using gulp watch, the styles, scripts and inject function works well.But when I make any file changes the scripts and styles need to be loaded automatically. This is not working.

I have tried adding gulp.series to each function.

    function isOnlyChange(event) {
      return event.type === 'changed';
      }

   gulp.watch([
     path.join(conf.paths.src, '/app/**/*.css'),
     path.join(conf.paths.src, '/app/**/*.scss')
    ], gulp.series(function (event) {
        if (isOnlyChange(event)) {
          gulp.series('styles-reload');
       } else {
         gulp.series('inject-reload');
       }
   }));

Gulp watch needs to reload styles when I make changes in styles file but this is not performing. Can someone help me out how to perform in gulp 4.x

Ragini
  • 13
  • 3

1 Answers1

0

You might try something like this:

function myWatch() {

  gulp.watch(['./scss/*.scss'], { events: 'change' }, function (cb) {
    console.log("here 1");
    // gulp.series('styles-reload');
    cb();
  });

  gulp.watch(['./scss/*.scss'], { events: ['add', 'addDir', 'unlink', 'unlinkDir', 'ready', 'error'] }, function (cb) {
    console.log("here 2");
    // gulp.series('inject-reload');
    cb();
  });
}

See https://gulpjs.com/docs/en/api/watch#options to see a description of the events you can include in the second gulp.watch.

Mark
  • 143,421
  • 24
  • 428
  • 436