2018-11-06 16:57:51 +00:00
|
|
|
import autoprefixer from "autoprefixer";
|
|
|
|
import browserSync from "browser-sync";
|
2018-12-16 21:27:09 +00:00
|
|
|
import { spawn } from "child_process";
|
2018-11-06 16:57:51 +00:00
|
|
|
import cssnano from "cssnano";
|
2018-12-16 21:27:09 +00:00
|
|
|
import { dest, series, src, task, watch } from "gulp";
|
2018-11-06 16:57:51 +00:00
|
|
|
import gulpif from "gulp-if";
|
2018-08-10 03:54:58 +00:00
|
|
|
import postcss from "gulp-postcss";
|
|
|
|
import purgecss from "gulp-purgecss";
|
2018-12-16 21:27:09 +00:00
|
|
|
import sourcemaps from "gulp-sourcemaps";
|
|
|
|
import atimport from "postcss-import";
|
2018-08-10 03:54:58 +00:00
|
|
|
import tailwindcss from "tailwindcss";
|
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
const rawStylesheet = "src/style.css";
|
2018-03-11 05:37:24 +00:00
|
|
|
const siteRoot = "_site";
|
2018-12-16 21:27:09 +00:00
|
|
|
const cssRoot = `${siteRoot}/assets/css/`;
|
|
|
|
const tailwindConfig = "tailwind.config.js";
|
2017-11-21 01:37:43 +00:00
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
const devBuild =
|
|
|
|
(process.env.NODE_ENV || "development").trim().toLowerCase() ===
|
|
|
|
"development";
|
2018-08-10 03:54:58 +00:00
|
|
|
|
2018-11-06 16:57:51 +00:00
|
|
|
// Fix for Windows compatibility
|
|
|
|
const jekyll = process.platform === "win32" ? "jekyll.bat" : "jekyll";
|
2017-11-09 02:34:49 +00:00
|
|
|
|
2018-11-06 16:57:51 +00:00
|
|
|
// Custom PurgeCSS Extractor
|
|
|
|
// https://github.com/FullHuman/purgecss
|
2018-02-09 05:15:15 +00:00
|
|
|
class TailwindExtractor {
|
|
|
|
static extract(content) {
|
2018-11-06 16:57:51 +00:00
|
|
|
return content.match(/[A-z0-9-:\/]+/g) || [];
|
2018-02-09 05:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
task("buildJekyll", () => {
|
2018-11-06 16:57:51 +00:00
|
|
|
browserSync.notify("Building Jekyll site...");
|
2018-12-16 21:27:09 +00:00
|
|
|
|
2018-11-06 16:57:51 +00:00
|
|
|
const args = ["exec", jekyll, "build"];
|
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
if (devBuild) {
|
|
|
|
args.push("--incremental");
|
|
|
|
}
|
2018-11-06 16:57:51 +00:00
|
|
|
|
|
|
|
return spawn("bundle", args, { stdio: "inherit" });
|
|
|
|
});
|
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
task("processStyles", done => {
|
|
|
|
browserSync.notify("Compiling styles...");
|
2018-11-06 16:57:51 +00:00
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
return src(rawStylesheet)
|
2018-02-09 05:15:15 +00:00
|
|
|
.pipe(postcss([atimport(), tailwindcss(tailwindConfig)]))
|
2018-11-06 16:57:51 +00:00
|
|
|
.pipe(gulpif(devBuild, sourcemaps.init()))
|
2018-12-16 21:27:09 +00:00
|
|
|
.pipe(
|
|
|
|
gulpif(
|
|
|
|
!devBuild,
|
|
|
|
new purgecss({
|
|
|
|
content: ["_site/**/*.html"],
|
|
|
|
extractors: [
|
|
|
|
{
|
|
|
|
extractor: TailwindExtractor,
|
|
|
|
extensions: ["html", "js"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2018-11-06 16:57:51 +00:00
|
|
|
.pipe(gulpif(!devBuild, postcss([autoprefixer(), cssnano()])))
|
2018-12-16 21:27:09 +00:00
|
|
|
.pipe(gulpif(devBuild, sourcemaps.write("")))
|
|
|
|
.pipe(dest(cssRoot));
|
|
|
|
});
|
2018-11-06 16:57:51 +00:00
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
task("startServer", () => {
|
2017-11-09 02:34:49 +00:00
|
|
|
browserSync.init({
|
2018-02-09 05:15:15 +00:00
|
|
|
files: [siteRoot + "/**"],
|
2017-11-21 01:24:25 +00:00
|
|
|
open: "local",
|
2018-02-09 05:15:15 +00:00
|
|
|
port: 4000,
|
2017-11-09 02:34:49 +00:00
|
|
|
server: {
|
|
|
|
baseDir: siteRoot
|
|
|
|
}
|
|
|
|
});
|
2017-11-11 08:26:29 +00:00
|
|
|
|
2018-11-06 16:57:51 +00:00
|
|
|
watch(
|
2018-02-13 02:37:11 +00:00
|
|
|
[
|
2019-01-13 19:53:49 +00:00
|
|
|
"**/*.css",
|
2019-01-13 19:30:12 +00:00
|
|
|
"**/*.gif",
|
2018-02-13 02:37:11 +00:00
|
|
|
"**/*.html",
|
2019-01-13 19:30:12 +00:00
|
|
|
"**/*.jpg",
|
2019-01-13 19:53:49 +00:00
|
|
|
"**/*.jpeg",
|
|
|
|
"**/*.js",
|
2018-02-13 02:37:11 +00:00
|
|
|
"**/*.md",
|
2019-01-13 19:30:12 +00:00
|
|
|
"**/*.png",
|
2018-02-13 02:37:11 +00:00
|
|
|
"**/*.yml",
|
|
|
|
"!_site/**/*",
|
|
|
|
"!node_modules"
|
2018-12-16 21:27:09 +00:00
|
|
|
],
|
|
|
|
{ interval: 500 },
|
2018-08-10 03:54:58 +00:00
|
|
|
buildSite
|
2018-02-09 05:15:15 +00:00
|
|
|
);
|
2018-11-06 16:57:51 +00:00
|
|
|
});
|
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
const buildSite = series("buildJekyll", "processStyles");
|
2017-11-09 02:34:49 +00:00
|
|
|
|
2018-12-16 21:27:09 +00:00
|
|
|
exports.serve = series(buildSite, "startServer");
|
2018-11-06 16:57:51 +00:00
|
|
|
exports.default = series(buildSite);
|