admin管理员组文章数量:1130349
I'm trying to render each file in my gulp source files with it's own json file, but I can't figure out how to access the current filename in the pipe function.
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/' + filename +'.json') }, options))
.pipe(gulp.dest('./build/'));
});
Where I can get it to work with the same file each time by just using require('./data/orders-plete.json'):
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/orders-plete.json') }, options))
.pipe(gulp.dest('./build/'));
});
It's not clear how I would do this.
I'm trying to render each file in my gulp source files with it's own json file, but I can't figure out how to access the current filename in the pipe function.
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/' + filename +'.json') }, options))
.pipe(gulp.dest('./build/'));
});
Where I can get it to work with the same file each time by just using require('./data/orders-plete.json'):
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/orders-plete.json') }, options))
.pipe(gulp.dest('./build/'));
});
It's not clear how I would do this.
Share Improve this question asked Oct 19, 2015 at 1:58 JP SilvashyJP Silvashy 48.6k50 gold badges153 silver badges230 bronze badges 2- 2 Sounds like you need something like gulp-tap to expose your file paths, see this answer – 1cgonza Commented Oct 19, 2015 at 3:56
- Did you manage to get it working? Can't achieve the desired effect with gulp-tap – eugenesqr Commented Nov 30, 2016 at 17:48
1 Answer
Reset to default 4Use gulp-tap, it enables you to get the file name and even change it for downstream pipes.
I'm trying to render each file in my gulp source files with it's own json file, but I can't figure out how to access the current filename in the pipe function.
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/' + filename +'.json') }, options))
.pipe(gulp.dest('./build/'));
});
Where I can get it to work with the same file each time by just using require('./data/orders-plete.json'):
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/orders-plete.json') }, options))
.pipe(gulp.dest('./build/'));
});
It's not clear how I would do this.
I'm trying to render each file in my gulp source files with it's own json file, but I can't figure out how to access the current filename in the pipe function.
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/' + filename +'.json') }, options))
.pipe(gulp.dest('./build/'));
});
Where I can get it to work with the same file each time by just using require('./data/orders-plete.json'):
var gulp = require('gulp');
var handlebars = require('handlebars');
var gulpHandlebars = require('gulp-pile-handlebars');
gulp.task('pile-with-sample-data', function () {
var options = {}
return gulp.src('./src/**/*.html')
.pipe(gulpHandlebars({ data: require('./data/orders-plete.json') }, options))
.pipe(gulp.dest('./build/'));
});
It's not clear how I would do this.
Share Improve this question asked Oct 19, 2015 at 1:58 JP SilvashyJP Silvashy 48.6k50 gold badges153 silver badges230 bronze badges 2- 2 Sounds like you need something like gulp-tap to expose your file paths, see this answer – 1cgonza Commented Oct 19, 2015 at 3:56
- Did you manage to get it working? Can't achieve the desired effect with gulp-tap – eugenesqr Commented Nov 30, 2016 at 17:48
1 Answer
Reset to default 4Use gulp-tap, it enables you to get the file name and even change it for downstream pipes.
本文标签: javascriptGulpusing current filename in pipe() functionStack Overflow
版权声明:本文标题:javascript - Gulp, using current filename in `pipe()` function - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1744587806a2105313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论