forked from vacp2p/vac.dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
97 lines (81 loc) · 2.26 KB
/
gulpfile.babel.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
import autoprefixer from "autoprefixer";
import browserSync from "browser-sync";
import spawn from "cross-spawn";
import cssnano from "cssnano";
import { dest, series, src, task, watch } from "gulp";
import postcss from "gulp-postcss";
import atimport from "postcss-import";
import imagemin from "gulp-imagemin";
import tailwindcss from "tailwindcss";
const SITE_ROOT = "./_site";
const POST_BUILD_STYLESHEET = `${SITE_ROOT}/assets/css/`;
const PRE_BUILD_STYLESHEET = "./assets/css/style.css";
const IMAGES = "./assets/img";
const IMAGES_MINIMIZED = `${SITE_ROOT}/assets/`;
const TAILWIND_CONFIG = "./tailwind.config.js";
// Fix for Windows compatibility
const jekyll = process.platform === "win32" ? "jekyll.bat" : "jekyll";
const isDevelopmentBuild = process.env.NODE_ENV === "development";
task("buildJekyll", () => {
browserSync.notify("Building Jekyll site...");
const args = ["exec", jekyll, "build"];
if (isDevelopmentBuild) {
args.push("--incremental");
}
return spawn("bundle", args, { stdio: "inherit" });
});
task("processStyles", () => {
browserSync.notify("Compiling styles...");
return src(PRE_BUILD_STYLESHEET)
.pipe(
postcss([
atimport(),
tailwindcss(TAILWIND_CONFIG),
...(isDevelopmentBuild ? [] : [autoprefixer(), cssnano()]),
])
)
.pipe(dest(POST_BUILD_STYLESHEET));
});
task("cname", () => {
return src('assets/CNAME').pipe(dest(SITE_ROOT));
});
task("images", () => {
return src(IMAGES)
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo(),
])
)
.pipe(dest(IMAGES_MINIMIZED));
});
task("startServer", () => {
browserSync.init({
files: [SITE_ROOT + "/**"],
open: "local",
port: 4000,
server: {
baseDir: SITE_ROOT,
serveStaticOptions: {
extensions: ["html"],
},
},
});
watch(
[
"**/*.css",
"**/*.html",
"**/*.js",
"**/*.md",
"**/*.markdown",
"!_site/**/*",
"!node_modules/**/*",
],
{ interval: 500 },
buildSite
);
});
const buildSite = series("buildJekyll", "processStyles", "images", "cname");
exports.serve = series(buildSite, "startServer");
exports.default = series(buildSite);