-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
53 lines (43 loc) · 1.5 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var nunjucks = require('gulp-nunjucks');
var nunjucksRender = require('gulp-nunjucks-render');
// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src("app/scss/main.scss")
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest("app/css"))
.pipe(browserSync.stream());
});
gulp.task('nunjucks', function() {
var manageEnvironment = function(environment) {
environment.addGlobal('globalTitle', 'My global title');
environment.addFilter('slug', function(str) {
return str && str.replace(/\s/g, '-', str).toLowerCase();
});
}
return gulp.src('app/pages/**/*.+(html|nunjucks)')
// Adding data to Nunjucks
//.pipe(data(function() {
// return require('./app/data.json')
//}))
.pipe(nunjucksRender({
path: 'app/templates/',
manageEnv: manageEnvironment
}))
.pipe(gulp.dest('app'))
});
// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./app",
online: false,
directory: true,
open: true
});
gulp.watch(['app/pages/**/*.+(html|nunjucks)','app/templates/**/*.+(html|nunjucks)'], ['nunjucks']);
gulp.watch("app/scss/**/*.scss", ['sass']);
gulp.watch("app/*.html").on('change', browserSync.reload);
});
gulp.task('default', ['serve']);