Add a JSON formatted file to a gulp stream.
This module requires node.js 13.8.0 or above.
npm i -D gulp gulp-add-json-file
import {promisify} from 'util';
import stream from 'stream';
import gulp from 'gulp';
import gulpAddJSON from 'gulp-add-json-file';
const pipeline = promisify(stream.pipeline);
gulp.task('default', () => {
/* Copy 'src/**' to 'dest', add 'filename.json' from JS object. */
return pipeline(
gulp.src('src/**'),
gulpAddJSON('filename.json', {field: 'value'}),
gulp.dest('dest')
);
});
- filename: The filename to use when adding a vinyl object
- object: The JavaScript object to stringify as contents of the vinyl object
- space: Passed directly to JSON.stringify.
Literal code points U+2028 and U+2029 are escaped for maximum compatibility.
This module should not be used to add a duplicate filename to the gulp stream. In
the above example if src/filename.json
exists it should be filtered out from
gulp.src
.