-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (63 loc) · 1.64 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var gulp = require('gulp'),
sass = require('gulp-sass'),
sassGlob = require('gulp-sass-glob'),
sourcemaps = require('gulp-sourcemaps'),
plumber = require('gulp-plumber'),
server = require('gulp-server-livereload'),
browserSync = require('browser-sync'),
nunjucksRender = require('gulp-nunjucks-render');
var stylesSrc = 'src/scss/[^_]*.scss'
var stylesDest = 'dest/css/'
gulp.task('default', ['styles', 'nunjucks', 'webserver']);
// Styles Task
gulp.task('styles', function () {
gulp.src(stylesSrc)
.pipe(plumber())
.pipe(sassGlob())
.pipe(sass({outputStyle: 'compressed'}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(stylesDest))
.pipe(browserSync.reload({
stream: true
}));
});
// Watch Styles Task
gulp.task('watch', function(){
gulp.watch('src/scss/**/*.scss', ['styles']);
gulp.watch('pages/**/*.html', ['nunjucks']);
gulp.watch('templates/**/*.html', ['nunjucks']);
});
// Compile Nunjucks Task
gulp.task('nunjucks', ['browserSync'], function() {
// Gets .html and .nunjucks files in pages
gulp.src('pages/**/*.+(html|nunjucks)')
.pipe(plumber())
// Renders template with nunjucks
.pipe(nunjucksRender({
path: ['templates']
}))
// output files in app folder
.pipe(gulp.dest('./'))
// reload browser
.pipe(browserSync.reload({
stream: true
}));
});
// Browser Sync
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: './'
},
})
})
// Web Server Task
gulp.task('webserver', ['watch'], function() {
gulp.src('./')
.pipe(server({
defaultFile: 'index.html',
livereload: true,
directoryListing: false,
open: true
}));
});