简体   繁体   English

从 gulp 3.x 迁移到 gulp 4.x 时,浏览器同步、脚本和 styles 重新加载不起作用

[英]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. 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.我尝试将 gulp.series 添加到每个 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.当我在 styles 文件中进行更改时,Gulp 手表需要重新加载 styles 但这没有执行。 Can someone help me out how to perform in gulp 4.x有人可以帮助我如何在 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 .请参阅https://gulpjs.com/docs/en/api/watch#options以查看您可以包含在第二个gulp.watch中的事件的描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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