簡體   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. 這是行不通的。

我嘗試將 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');
       }
   }));

當我在 styles 文件中進行更改時,Gulp 手表需要重新加載 styles 但這沒有執行。 有人可以幫助我如何在 gulp 4.x 中執行

你可以嘗試這樣的事情:

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();
  });
}

請參閱https://gulpjs.com/docs/en/api/watch#options以查看您可以包含在第二個gulp.watch中的事件的描述。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM