How to perform multiple gulp commands in one task

自古美人都是妖i 提交于 2019-12-20 09:48:37

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/25713118/how-to-perform-multiple-gulp-commands-in-one-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!