-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
56 lines (48 loc) · 1.54 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
44
45
46
47
48
49
50
51
52
53
54
55
56
// gulpfile.js
const gulp = require('gulp'),
browserSync = require('browser-sync').create(),
htmlmin = require('gulp-htmlmin'),
nunjucksRender = require('gulp-nunjucks-render'); // importing the plugin
const PATHS = {
output: 'dist',
templates: 'src/templates',
pages: 'src/pages',
}
// writing up the gulp nunjucks task
gulp.task('nunjucks', function() {
console.log('Rendering nunjucks files..');
return gulp.src(PATHS.pages + '/**/*.+(html|js|css)')
.pipe(nunjucksRender({
path: [PATHS.templates],
watch: true,
}))
.pipe(gulp.dest(PATHS.output));
});
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: PATHS.output
},
});
});
gulp.task('watch', function() {
// trigger Nunjucks render when pages or templates changes
gulp.watch([PATHS.pages + '/**/*.+(html|js|css)', PATHS.templates + '/**/*.+(html|js|css)'], ['nunjucks'])
// reload browsersync when `dist` changes
gulp.watch(PATHS.output + '/*').on('change', browserSync.reload);
});
gulp.task('minify', function() {
return gulp.src(PATHS.output + '/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
cssmin: true,
jsmin: true,
removeOptionalTags: true,
removeComments: false
}))
.pipe(gulp.dest(PATHS.output));
});
// run browserSync auto-reload together with nunjucks auto-render
gulp.task('auto', ['browserSync', 'watch']);
//default task to be run with gulp
gulp.task('default', ['nunjucks']);