Home

Awesome

gulp-eval

Require CommonJS modules, JSON files or files with JS-expression inside gulp tasks with ease.

NPM version Build Status Coverage Status Dependency Status

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

License

Code and documentation © 2016 YANDEX LLC. Code released under the Mozilla Public License 2.0