Skip to content

Instantly share code, notes, and snippets.

@867
Last active March 11, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 867/5f1d14c0a0818b64fa57b2b6d6c89739 to your computer and use it in GitHub Desktop.
Save 867/5f1d14c0a0818b64fa57b2b6d6c89739 to your computer and use it in GitHub Desktop.
公式ブログ用:gulpfile.js : gulp-fs
'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