Last active
July 9, 2018 10:51
-
-
Save 867/45386ee17056483d93d09d17283fb154 to your computer and use it in GitHub Desktop.
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 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