简体   繁体   中英

Browser-sync, scripts and styles reload not working when migrating from gulp 3.x to gulp 4.x

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM