Skip to content

Instantly share code, notes, and snippets.

@867
Last active July 9, 2018 10:51
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/45386ee17056483d93d09d17283fb154 to your computer and use it in GitHub Desktop.
Save 867/45386ee17056483d93d09d17283fb154 to your computer and use it in GitHub Desktop.
'use strict';
const gulp = require('gulp');
const nunjucks = require('gulp-nunjucks-render');
const data = require('gulp-data');
const beautify = require('gulp-html-beautify');
const brsync = require('browser-sync');
const paths = {
'src' : {
'root' : 'src/',
'template' : 'src/template/',
'html' : 'src/template/page/',
'json' : './src/template/data/site.json'
},
'dest' : {
'root' : 'html/'
}
}
const beautify_option = {
'indent_size': 2
}
// task:nunjucks
gulp.task('nunjucks', function(){
return gulp.src(paths.src.html + '**/*.njk')
.pipe(data(function(){
return require(paths.src.json);
}))
.pipe(nunjucks({
path: paths.src.template
}))
.pipe(beautify(beautify_option))
.pipe(gulp.dest(paths.dest.root))
});
// task:brsync
gulp.task('brsync', function(){
brsync.init({
notify: false,
server: paths.dest.root
});
});
// task:reload
gulp.task('reload', function(){
brsync.reload();
});
// task:watch
gulp.task('watch', function(){
gulp.watch(paths.src.template + '**/*.njk', ['nunjucks']);
gulp.watch(paths.dest.root + '**/*.html', ['reload']);
});
// task:default
gulp.task('default', ['brsync', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment