Gulp using the current file name in the `pipe ()` function

I am trying to display each file in gulp source files with its own json file, but I cannot figure out how to access the current file name in pipe .

 var gulp = require('gulp'); var handlebars = require('handlebars'); var gulpHandlebars = require('gulp-compile-handlebars'); gulp.task('compile-with-sample-data', function () { var options = {} return gulp.src('./src/**/*.html') .pipe(gulpHandlebars({ data: require('./data/' + filename +'.json') }, options)) .pipe(gulp.dest('./build/')); }); 

Where can I get it to work with the same file every time, simply using require('./data/orders-complete.json') :

 var gulp = require('gulp'); var handlebars = require('handlebars'); var gulpHandlebars = require('gulp-compile-handlebars'); gulp.task('compile-with-sample-data', function () { var options = {} return gulp.src('./src/**/*.html') .pipe(gulpHandlebars({ data: require('./data/orders-complete.json') }, options)) .pipe(gulp.dest('./build/')); }); 

It is not clear how I will do this.

+7
javascript gulp
source share
1 answer

Use gulp-tap , it allows you to get the file name and even change it for subsequent channels.

+4
source share

All Articles