Created
August 29, 2016 18:11
-
-
Save sh4869/888cc937155be992d291137a481dad5a to your computer and use it in GitHub Desktop.
Gulpでjsonファイルをいい感じに読み込みたい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var pug = require('gulp-pug'); | |
var data = require('gulp-data'); | |
var fs = require('fs'); | |
// hamlタスク設定 | |
gulp.task('pug', function() { | |
taskname = this.seq.slice(-1)[0] | |
gulp.src(['./*/*.pug','./*.pug'],{base:'./'}) | |
.pipe(data(function(file){ | |
var dirname = "./json/"; | |
var files = fs.readdirSync(dirname); | |
var json = {}; | |
files.forEach(function(filename){ | |
json[filename.replace(".json","")] = require(dirname + filename); | |
}); | |
return {data:json}; | |
})) | |
.pipe(pug({pretty: true})) | |
.pipe(gulp.dest('./')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment