-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
89 lines (80 loc) · 1.97 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
77
78
79
80
81
82
83
84
85
86
87
88
89
// Dependencies
const gulp = require('gulp');
const gulpSass = require('gulp-sass')(require('sass'));
const gulpBrowserSync = require('browser-sync').create();
const gulpNunjucksRender = require('gulp-nunjucks-render');
const del = require('del');
// Configuration
const pages = 'src/pages';
const templates = 'src/templates';
const css = 'src/styles';
const fonts = 'src/styles/fonts';
const output = 'dist';
const cssOutput = 'dist/styles';
const fontsOutput = 'dist/styles/fonts';
// CSS sass
function sass() {
return gulp
.src(css + '/*.+(css|scss)')
.pipe(gulpSass())
.pipe(gulp.dest(cssOutput))
.pipe(gulpBrowserSync.stream());
}
// CSS Fonts
async function copyFonts() {
return gulp.src(fonts + '/**/*').pipe(gulp.dest(fontsOutput));
}
// Templates nunjucks
function nunjucks() {
return gulp
.src(pages + '/**/*.+(html|njk)')
.pipe(
gulpNunjucksRender({
path: templates,
lstripBlocks: true,
trimBlocks: true,
})
)
.pipe(gulp.dest(output))
.pipe(gulpBrowserSync.stream());
}
// Watch for CSS changes
function watchCSS() {
return gulp
.watch(css, { ignoreInitial: false }, sass)
.on('change', gulpBrowserSync.reload);
}
// Watch for pages changes
function watchPages() {
return gulp
.watch(pages, { ignoreInitial: false }, nunjucks)
.on('change', gulpBrowserSync.reload);
}
// // Watch for templates changes
function watchTemplates() {
return gulp
.watch(templates, { ignoreInitial: false }, nunjucks)
.on('change', gulpBrowserSync.reload);
}
// Static Server
function browserSync() {
gulpBrowserSync.init({
server: {
baseDir: output,
},
notify: false,
});
}
// Clean output
function clean() {
return del([output]);
}
// Export tasks
exports.build = gulp.series(
clean,
gulp.parallel(sass, copyFonts, nunjucks),
browserSync
);
exports.watch = gulp.parallel(watchCSS, watchPages, watchTemplates);
// Run
exports.default = gulp.parallel(exports.build, exports.watch);