-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
114 lines (104 loc) · 2.7 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// gulp core
const gulp = require("gulp");
// some aliases for qol
const series = gulp.series;
const parallel = gulp.parallel;
// html
const pug = require("gulp-pug");
// css
const sass = require("gulp-sass");
const cleanCSS = require("gulp-clean-css");
// images
const imagemin = require("gulp-imagemin");
// utils
const pj = require("path").join; // aliasing to pj for ease of use
const bsync = require("browser-sync");
const clean = require("gulp-clean");
const ghpages = require("gulp-gh-pages");
const srcdir = "src";
const destdir = "dist";
const paths = {
sass: {
src: pj(srcdir, "**/*.sass"),
dest: pj(destdir)
},
pug: {
src: [pj(srcdir, "**/*.pug"), "!"+pj(srcdir, '**/_*/**/*')],
dest: pj(destdir)
},
img: {
src: pj(srcdir, "**/*.{png,jpg,svg,gif}"),
dest: pj(destdir)
},
files: {
src: pj(srcdir, "/**/*{.txt,.asc,.pub,CNAME}"),
dest: pj(destdir)
}
};
// render all Pug to HTML
gulp.task("html", () => {
return gulp
.src(paths.pug.src)
.pipe(pug())
.pipe(gulp.dest(paths.pug.dest))
.pipe(bsync.stream());
});
// Render all SASS to CSS
gulp.task("css", () => {
return gulp
.src(paths.sass.src)
.pipe(sass())
.pipe(cleanCSS())
.pipe(gulp.dest(paths.sass.dest))
.pipe(bsync.stream());
});
// Optimize images in the src dir
gulp.task("img", () => {
return gulp
.src(paths.img.src)
.pipe(imagemin())
.pipe(gulp.dest(paths.img.dest))
.pipe(bsync.stream());
});
// Copy all files to the dist dir
gulp.task("files", () => {
return gulp
.src(paths.files.src)
.pipe(gulp.dest(paths.files.dest))
.pipe(bsync.stream());
});
// Clean the entire dist folder
gulp.task("clean", () => {
return gulp.src(destdir, { read: false, allowEmpty: true }).pipe(clean());
});
// Build batch job
gulp.task("build", series("clean", parallel("html", "css", "img", "files")));
// Auto-refreshing dev server
gulp.task(
"watch",
series("build", () => {
// start browsersync server
bsync.init({
server: {
baseDir: destdir
}
});
gulp.watch(paths.pug.src, series("html"));
gulp.watch(paths.sass.src, series("css"));
gulp.watch(paths.img.src, series("img"));
gulp.watch(paths.files.src, series("files"));
})
);
gulp.task("dev", series("watch"));
// GitHub pages tasks
gulp.task("gh-pages", () => {
return gulp.src(pj(destdir, "**/*")).pipe(ghpages());
});
gulp.task("move-cname", () => {
// add CNAME to the build so the redirect doesn't break when we push
return gulp.src(pj(srcdir, "CNAME")).pipe(gulp.dest(destdir));
});
// deploy to github pages
gulp.task("publish", series("build", "move-cname", "gh-pages"));
gulp.task("deploy", series("publish"));
gulp.task("default", series("build"));