-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.babel.js
127 lines (110 loc) · 3.08 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import autoprefixer from "autoprefixer";
import browserSync from "browser-sync";
import { spawn } from "child_process";
import cssnano from "cssnano";
import { dest, series, src, task, watch } from "gulp";
import gulpif from "gulp-if";
import postcss from "gulp-postcss";
import postcssNested from 'postcss-nested';
import postcssExtend from 'postcss-extend';
import purgecss from "gulp-purgecss";
import sourcemaps from "gulp-sourcemaps";
import atimport from "postcss-import";
import tailwindcss from "tailwindcss";
import babel from 'gulp-babel';
import webpack from 'webpack-stream';
import compiler from 'webpack';
const rawStylesheet = "src/css/style.css";
const siteRoot = "_site";
const cssRoot = `${siteRoot}/assets/css/`;
const jsRoot = `${siteRoot}/assets/js/`;
const tailwindConfig = "tailwind.config.js";
const devBuild =
(process.env.NODE_ENV || "development").trim().toLowerCase() ===
"development";
// Fix for Windows compatibility
const jekyll = process.platform === "win32" ? "jekyll.bat" : "jekyll";
// Custom PurgeCSS Extractor
// https://github.com/FullHuman/purgecss
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g) || [];
}
}
task("buildJekyll", () => {
browserSync.notify("Building Jekyll site...");
const args = ["exec", jekyll, "build"];
if (devBuild) {
args.push("--incremental");
}
return spawn("bundle", args, { stdio: "inherit" });
});
task("processStyles", done => {
browserSync.notify("Compiling styles...");
return src(rawStylesheet)
.pipe(postcss([atimport(), tailwindcss(tailwindConfig),postcssExtend(), postcssNested()]))
.pipe(gulpif(devBuild, sourcemaps.init()))
.pipe(
gulpif(
!devBuild,
new purgecss({
content: ["**/*.html"],
whitelist: ['is-active', 'shrink'],
extractors: [
{
extractor: TailwindExtractor,
extensions: ["html", "js"]
}
]
})
)
)
.pipe(gulpif(!devBuild, postcss([autoprefixer(), cssnano()])))
.pipe(gulpif(devBuild, sourcemaps.write("")))
.pipe(dest(cssRoot));
});
task('processScripts', done => {
return src('src/js/entry.js')
.pipe(webpack({
mode: 'production',
entry: {
global: './src/js/global.js',
home: './src/js/home.js',
presentation: './src/js/presentation.js',
},
output: {
filename: '[name].js',
},
}, compiler, function(err, stats) {
}))
.pipe(dest(jsRoot));
});
task("startServer", () => {
browserSync.init({
files: [siteRoot + "/**"],
open: "local",
port: 4000,
server: {
baseDir: siteRoot,
serveStaticOptions: {
extensions: ["html"]
}
}
});
watch(
[
"**/*.css",
"**/*.html",
"**/*.js",
"**/*.md",
"**/*.markdown",
"!_site/**/*",
"!node_modules/**/*"
],
{ interval: 500 },
buildSite
);
});
const buildSite = series("buildJekyll", "processStyles", "processScripts");
exports.serve = series(buildSite, "startServer");
exports.default = series(buildSite);