Last active
March 11, 2019 04:05
-
-
Save 867/5f1d14c0a0818b64fa57b2b6d6c89739 to your computer and use it in GitHub Desktop.
公式ブログ用:gulpfile.js : gulp-fs
This file contains 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
'use strict'; | |
const gulp = require('gulp'); | |
const nunjucks = require('gulp-nunjucks-render'); | |
const data = require('gulp-data'); | |
const fs = require('fs'); | |
const paths = { | |
'src' : { | |
'root' : 'src/', | |
'template' : 'src/template/', | |
'html' : 'src/template/page/', | |
'json' : 'src/template/data/', | |
'json_news' : './src/template/data/news.json' | |
}, | |
'dest' : { | |
'root' : 'html/' | |
} | |
} | |
// task:nunjucks | |
gulp.task('nunjucks', function(){ | |
return gulp.src(paths.src.html + '**/*.njk') | |
.pipe(data(function(file) { | |
return JSON.parse(fs.readFileSync(paths.src.json_news)); | |
})) | |
.pipe(nunjucks({ | |
path: paths.src.template | |
})) | |
.pipe(gulp.dest(paths.dest.root)) | |
}); | |
// task:watch | |
gulp.task('watch', function(){ | |
gulp.watch(paths.src.json + '**/*.json', ['nunjucks']); | |
gulp.watch(paths.src.template + '**/*.njk', ['nunjucks']); | |
}); | |
// task:default | |
gulp.task('default', ['watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment