How to pipe YAML into EJS in a Gulp stream?

shennan

I'm using gulp.js. I want to pipe the resulting JSON data from gulp-yaml, straight into gulp-ejs. My logic says that I'm probably going to have to get synchronous at some point?

What I have tried thus far:

var yaml = require('gulp-yaml');
var ejs = require('gulp-ejs');

gulp.task('yaml', function(){

    return gulp.src('./path/to/template.ejs')
        .pipe( ejs( gulp.src('./path/to/data.yml').pipe( yaml() ) ) )
        .pipe(gulp.dest('./path/to/dest'));

});

I realise that the above is an idiotic script as I'm essentially trying to pass a stream as an argument to ejs. And as predicted, it doesn't work. I've tried numerous other things but I'm guessing someone has done this before?

I reckon gulp-data will have something to do with the solution...

Ben

You probably don't need the gulp-data plugin to achieve this; like you said you're just passing the option synchronously to the ejs plugin, and you're only needing the one yaml config file. So this is probably better:

var yaml = require('js-yaml');
var ejs = require('gulp-ejs');
var fs = require('fs');

gulp.task('ejs-with-yaml', function () {
    return gulp.src('path/to/template.ejs')
        .pipe(ejs(yaml.safeLoad(fs.readFileSync('path/to/data.yml', 'utf-8'))))
        .pipe(gulp.dest('path/to/dest'));
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pipe YAML into EJS in a Gulp stream?

From Dev

Gulp / Unhandled stream error in pipe

From Dev

gulp - how to pipe tasks

From Dev

gulp - how to pipe tasks

From Dev

How to create repeating pipe in gulp?

From Dev

gulp-sass error: Unhandled stream error in pipe

From Dev

How to pipe a stream using pdfkit with node js

From Dev

How to pipe stream to reply in hapi.js

From Dev

How to pipe output of active stream to other commands

From Dev

How to render response after stream finished pipe?

From Dev

How read stream of gulp.src

From Dev

How to pipe what is written to Stream 1 into Stream 2?

From Dev

How can you pipe a readable stream to another readable stream?

From Dev

How can you pipe a readable stream to another readable stream?

From Dev

gulp.on('data') How to pass data to next pipe

From Dev

How can I pass gulp.watch() to a pipe?

From Dev

How can I write a simple gulp pipe function?

From Dev

How to set gulp.dest() in same directory as pipe inputs?

From Dev

Gulp pipe minimal function?

From Dev

Gulp condition inside pipe

From Dev

Linux pipe, fork and execlp: how to get the value written into stream 1

From Dev

How to create destination path for node.js stream pipe?

From Dev

How can I split and pipe multiple NAudio stream

From Dev

How to stream/pipe response object from Zombie.js

From Dev

How to stream/pipe response object from Zombie.js

From Dev

Node - how can i pipe to a new READABLE stream?

From Dev

Need help understanding how gulp and webpack-stream works

From Dev

How to use gulp webpack-stream to generate a proper named file?

From Dev

How to save a stream into multiple destinations with Gulp.js?

Related Related

HotTag

Archive