如何在一项任务中执行多个 gulp 命令 [英] How to perform multiple gulp commands in one task

查看:46
本文介绍了如何在一项任务中执行多个 gulp 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解如何在单个任务中处理多个 gulp 源.在这样的任务中:

I'm having a hard time to understand on how to process multiple gulp sources in a single task. In a task like this:

gulp.task('task1', function (cb) {
    gulp.src('src/js/**/*').pipe(gulp.dest('dist'));
    gulp.src('src/css/**/*').pipe(gulp.dest('dist'));
    ...
});

我想处理所有不同的源文件,然后将任务标记为已完成,因此其他任务可以依赖于它的完成.

I would like to process all the different source files and then mark the task as finished, so the others tasks can depend on it's completion.

我知道为每个单独的源使用单独的任务的可能性,但这会使一切变得更加复杂,并使编排器因大量实际上不需要单独的任务而膨胀.

I'm aware of the possibility, to using individual tasks for each individual source but this would make everything more complicated and bloat the orchestrator with a huge number of tasks that are actually not needed individually.

推荐答案

如果您对所有文件执行相同的操作,则可以将 glob 数组传递给 gulp.src.例如,

You can pass an array of globs to gulp.src if you are doing the same things to all files. For example,

gulp.task('task1', function () {
  return gulp.src(['src/js/**/*', 'src/css/**/*']).pipe(gulp.dest('dist'));
});

确保返回流,以便协调器知道该任务何时完成.

Be sure to return the stream so the orchestrator knows when that task is complete.

如果你对不同的文件集做不同的事情,你可以像这样在一个任务中合并流:

If you are doing different things to the different sets of files, you can merge the streams like this in one task:

var es = require('event-stream');
gulp.task('fancy-task', function () {
  return es.merge(
      gulp.src('*.js').pipe(some-js-plugin()),
      gulp.src('*.css').pipe(some-style-plugin))
      .pipe(gulp.dest('dist'));
});

这篇关于如何在一项任务中执行多个 gulp 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆