map each file in a stream into multiple files that are piped out
Install
$ npm install --save-dev gulp-flatmap
Usage
var gulp = require('gulp');
var flatmap = require('gulp-flatmap');
var uglify = require('gulp-uglify');
var path = require('path');
var concat = require('gulp-concat');
gulp.task('default', function () {
return gulp.src('*.json')
.pipe(flatmap(function(stream, file){
var contents = JSON.parse(file.contents.toString('utf8'));
return gulp.src(contents.files)
.pipe(uglify())
.pipe(concat(path.basename(file.path)));
}))
.pipe(gulp.dest('dist'));
});
API
The flatmap method takes one argument, a function. This function is called once for each file piped to flatmap
and is passed a stream as its first argument and the vinyl file as its second argument. The stream contains only one file.
You can optionally return a stream from the flatmap
function. All the streams returned from flatmap
will be combined and their contents will be emited by flatmap
.
License
MIT © Marius Gundersen