I need to pass a parameter to a gulp task from another task or replace a task with a function called by runSequence

牧云@^-^@ 提交于 2019-12-06 09:38:24

Ideally I would like the task that makes the Html to be a function that I can pass a parameter to

You can do just that, except you don't just pass your parameters to the function, but also a callback cb that will be called when your function is done:

function makeExHtml(files, cb) {
  return gulp.src(files, { base: process.cwd() })
    .pipe(print(function (file) {
        return "Found file " + file;
    }))
    .pipe(rename({ basename: 'base' }))
    .pipe(gulp.dest('./'))
    .on('end', cb);
}

In your gulp tasks you can then use the above makeExHtml() function and pass a callback that will execute the rest of your runSequence():

gulp.task('make_prod_ex1', function () {
  makeExHtml(config.srcEx1Html, function() {
    runSequence(
      'makeTemplate',
      'rename_bundle_css',
      'rename_bundle_js',
      function () {
        make_prod_index('ex1');
    });
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!