gulp-eval
v1.0.0
Published
require or eval modules
Downloads
448
Readme
gulp-eval
Require CommonJS modules, JSON files or files with JS-expression inside gulp tasks with ease.
gulp-eval
fills data
property of Vinyl objects.
Usage example:
var gulp = require('gulp');
var concat = require('gulp-concat');
var gulpEval = require('gulp-eval');
var through = require('through2');
gulp.task('default', () =>
gulp.src('node_modules/*/package.json')
.pipe(gulpEval())
.pipe(through.obj(function(file, enc, next) {
var data = file.data; // Here we have evaluated package.json
file.contents = new Buffer(data.name + '#' + data.version);
next(null, file);
}))
.pipe(concat('packages.txt'))
.pipe(gulp.dest('dest/'))
);
Context
You can provide some like-a-global variables into gulp-eval
var gulpEval = require('gulp-eval');
var globalVar = 42;
var transformStream = gulpEval({globalVar: globalVar});
// globalVar will be in context of evaluated code