Gulp using gulp-jade with gulp-data

落花浮王杯 提交于 2019-12-03 21:24:49

You are getting error because in getJsonData you pass required data as first argument to the callback. That is reserved for possible errors.

In your case the callback isn't needed. Looking at gulp-data usage example this should work:

.pipe(data(function(file) {
  return require('./data/' + path.basename(file.path) + '.json');
}))

Full example:

var gulp = require('gulp');
var jade = require('gulp-jade');
var data = require('gulp-data');
var path = require('path');
var fs   = require('fs');

gulp.task('jade', function() {
  return gulp.src('*.jade')
    .pipe(data(function(file) {
      return require('./data/' + path.basename(file.path) + '.json');
    }))
    .pipe(jade({ pretty: true }))
    .pipe(gulp.dest('build/'));
});

Use this if you're running the task on gulp.watch:

.pipe(data(function(file) {
  return JSON.parse(fs.readFileSync('./data/' + path.basename(file.path) + '.json'));
}))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!