Skip to content Skip to sidebar Skip to footer

How To Get A Gulp Stream From A Vinyl Object?

How can I create a stream using a vinyl object so I can use gulp.js plugins on it? Example with a vinyl object: var file = getFoo(); // An in-memory file as a vinyl object. return

Solution 1:

You can use vinyl-source-stream or equivalent (https://www.npmjs.com/package/gulp-streamify) and add new pipe to convert to the stream. You can explicitly do that with gulp-map like here

Solution 2:

File itself is a usable object

var file = getFoo();
return file
    .pipe(css(opts))
    .pipe(gulp.dest('...'));

Solution 3:

For two streams, use gulp-buffer

var buffer = require('gulp-buffer');

var file1 = getFoo();
var file2 = getBar();

returnmerge(file1, file2)      // (gulp-merge)
    .pipe(buffer())             // (gulp-buffer)
    .pipe(concat('foobar.css')) // (gulp-concat)
    .pipe(css(opts))
    .pipe(gulp.dest('...'));

Post a Comment for "How To Get A Gulp Stream From A Vinyl Object?"