jshanley
jshanley

Reputation: 9138

Gulp: run task without a destination

I'm trying to make a simple task to show the file size for each file in an array of paths using the gulp-size package, like so:

var gulp = require('gulp')
var size = require('gulp-size')

gulp.task('size', function() {
  gulp.src(bigArrayOfFilePathsFromAnotherModule)
    .pipe(size({ showFiles: true }))
})

When this runs, it gets part of the way through, but then the task finishes before all of the files are processed. It works just fine if I pipe them to a destination, but I'd rather not copy the files anywhere. Is there a way to pipe these files into a black hole so the task completes?

I've tried .pipe(gulp.dest('/dev/null')) but it errors out trying to mkdir /dev/null which already exists.

Is there a good way to pipe a stream to nowhere?

Upvotes: 6

Views: 1628

Answers (1)

Louis
Louis

Reputation: 151521

You should return your stream:

gulp.task('size', function() {
  return gulp.src(bigArrayOfFilePathsFromAnotherModule)
    .pipe(size({ showFiles: true }));
})

Otherwise, gulp will assume the work done by the task is synchronous and done by the time your anonymous function returns.

Upvotes: 8

Related Questions