-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
66 lines (57 loc) · 1.93 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
// Load node modules.
const bootstrap = require('bootstrap/package.json');
const browser = require('browser-sync');
const gulp = require('gulp');
const panini = require('panini');
const rimraf = require('rimraf');
const sass = require('gulp-sass');
// Run this using 'gulp clean'.
gulp.task('clean', gulp.series(clean));
// Run this using 'gulp build'.
gulp.task('build', gulp.series('clean', gulp.parallel(pages, style)));
// Run this using 'gulp'.
gulp.task('default', gulp.series('build', serve, watch));
// Compile HTML pages using Panini.
function pages() {
return gulp.src('./panini/pages/**/*.html')
.pipe(panini({
root: './panini/pages/',
layouts: './panini/layouts/',
partials: './panini/partials',
helpers: './panini/helpers',
data: './panini/data'
}))
.pipe(gulp.dest('.'));
}
// Compile CSS files using SASS.
function style() {
var bootstrapSrc = "./node_modules" + bootstrap._location + "/scss";
return gulp.src('./sass/**/*.scss')
.pipe(sass({includePaths: [bootstrapSrc]}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
}
// Refresh Panini when layout/partials is added/changed.
function resetPages(done) {
panini.refresh();
done();
}
// Remove HTML and CSS files from project folder.
function clean(done) {
rimraf('./css', function() {});
rimraf('./*.html', function () {});
done();
}
// Serve website using Browsersync.
function serve(done) {
browser.init({
server: './',
port: 8000
});
done();
}
// Watch any changes in the project folders and take appropriate actions.
function watch() {
gulp.watch('./panini/pages/**/*.html').on('all', gulp.series(pages, browser.reload));
gulp.watch('./panini/{layouts, partials}/**/*.html').on('all', gulp.series(resetPages, pages, browser.reload));
gulp.watch('./sass/**/*.scss').on('all', gulp.series(style, browser.reload));
}