【问题标题】:How to run gup task in series如何串联运行 gup 任务
【发布时间】:2023-03-23 04:32:01
【问题描述】:

我是 gulp 的新手。

我写了两个需要执行的任务。当我单独运行它们时,它们工作正常。但是当我将它们结合起来时,“替换”不起作用。

gulp.task('bundle-source', function () {
  return bundler.bundle(config);
});

gulp.task('bundle-config', function(){
   return gulp.src(['config.js'])
     .pipe(replace('src/*', 'dist/*'))
    .pipe(gulp.dest(''));
});

gulp.task('bundle', ['bundle-config', 'bundle-source']);

我认为问题在于它们都在操纵 config.js。我认为第二个任务保存到磁盘时会覆盖第一个所做的更改。第二个任务大约需要 30 秒。

【问题讨论】:

    标签: gulp gulp-replace


    【解决方案1】:

    Gulp 任务默认并行运行。因此,如果您的任务正在处理相同的文件,它们可能确实会互相踩踏。

    您可以使用 gulp 的任务依赖项让它们一个接一个地运行。所以如果bundle-config 应该在bundle-source 之前运行:

    gulp.task('bundle-source', ['bundle-config'], function () {
      return bundler.bundle(config);
    });
    

    如果您需要它们一个接一个地运行,您也可以使用像 run-sequence 这样的包:

    var seq = require('run-sequence');
    
    gulp.task('bundle', function(cb) {
        return seq('bundle-config', 'bundle-source', cb);
    });
    

    最后,您可以使用 gulp 4,它具有内置机制来串行运行任务。

    【讨论】:

      猜你喜欢
      • 2018-01-13
      • 1970-01-01
      • 2015-03-12
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 2013-02-23
      • 2010-10-09
      • 2012-05-30
      相关资源
      最近更新 更多