user2371684
user2371684

Reputation: 1555

gulp multiple sources in one task

In my project structure I have app folder for development, I would like to move the .html files and the content of /css to a folder above it called /dist.

In my gulp tasks I tried this:

gulp.task('prod', function() {
  gulp.src('app/*.html')
    .pipe(gulp.dest('dist'))
  gulp.src('app/css/*.css')
    .pipe(gulp.dest('dist/css'))
});

This didn't work out. The only way was to create two different tasks:

gulp.task('prod_html', function() {
  return gulp.src('app/*.html')
    .pipe(gulp.dest('dist'))
});

gulp.task('prod_css', function() {
  return gulp.src('app/css/*.css')
    .pipe(gulp.dest('dist/css'))

});

But this seems to be the bad practice to create servera different tasks in the end; one for the html files, then for /css and /js and /images

cheers Sohail

Upvotes: 1

Views: 1320

Answers (1)

user2371684
user2371684

Reputation: 1555

I ended up using merge-stream :)

npm install --save-dev gulp merge-stream

Then:

var merge = require('merge-stream');

gulp.task('prod', function() {
  var html = gulp.src('app/*.html')
    .pipe(gulp.dest('dist'))

  var css = gulp.src('app/css/*.css')
    .pipe(gulp.dest('dist/css'))

  return merge(html, css);
});

and put in my default tasks :)

Upvotes: 2

Related Questions