-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
43 lines (37 loc) · 1 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict'
const gulp = require('gulp');
const path = require('path');
const gutil = require('gulp-util');
const plumber = require('gulp-plumber');
const data = require('gulp-data');
const nunjucksRender = require('gulp-nunjucks-render');
const livereload = require('gulp-livereload');
function onError(error) {
gutil.log(error.message)
this.emit('end')
}
gulp.task('nunjucks', function() {
// Gets .html and .nunjucks files in pages
return gulp.src('pages/**/*.+(html|nunjucks)')
.pipe(plumber({errorHandler: onError}))
.pipe(data(function() {
return require('./data.json');
}))
// Renders template with nunjucks
.pipe(nunjucksRender({
path: ['templates']
}))
// output files in app folder
.pipe(gulp.dest('.'))
.pipe(livereload());
});
gulp.task('watch', () => {
livereload.listen();
gulp.watch([
path.join('templates', '**', '*.+(html|nunjucks)'),
path.join('pages', '**', '*.+(html|nunjucks)'),
'data.json'
],
['nunjucks'])
})
gulp.task('start', ['watch'])