2018-11-06 11:57:51 -05:00
|
|
|
import autoprefixer from "autoprefixer";
|
|
|
|
import browserSync from "browser-sync";
|
|
|
|
import cssnano from "cssnano";
|
2018-12-16 15:27:09 -06:00
|
|
|
import { dest, series, src, task, watch } from "gulp";
|
2018-08-09 22:54:58 -05:00
|
|
|
import postcss from "gulp-postcss";
|
2020-01-25 12:35:18 -06:00
|
|
|
import purgecss from "@fullhuman/postcss-purgecss";
|
2018-12-16 15:27:09 -06:00
|
|
|
import atimport from "postcss-import";
|
2018-08-09 22:54:58 -05:00
|
|
|
import tailwindcss from "tailwindcss";
|
|
|
|
|
2020-01-25 12:08:59 -06:00
|
|
|
const SITE_ROOT = "./_site";
|
|
|
|
const POST_BUILD_STYLESHEET = `${SITE_ROOT}/assets/css/`;
|
|
|
|
const PRE_BUILD_STYLESHEET = "./src/style.css";
|
|
|
|
const TAILWIND_CONFIG = "./tailwind.config.js";
|
2017-11-20 19:37:43 -06:00
|
|
|
|
2018-11-06 11:57:51 -05:00
|
|
|
// Fix for Windows compatibility
|
2020-01-25 12:40:26 -06:00
|
|
|
const isWindowsPlatform = process.platform === "win32";
|
|
|
|
const jekyll = isWindowsPlatform ? "jekyll.bat" : "jekyll";
|
2020-01-25 12:41:17 -06:00
|
|
|
const spawn = isWindowsPlatform
|
|
|
|
? require("win-spawn")
|
|
|
|
: require("child_process").spawn;
|
2017-11-08 20:34:49 -06:00
|
|
|
|
2020-01-25 12:45:15 -06:00
|
|
|
const isDevelopmentBuild = process.env.NODE_ENV === "development";
|
|
|
|
|
2020-01-25 12:35:18 -06:00
|
|
|
// Custom PurgeCSS Extractor for Tailwind CSS
|
2020-01-25 18:48:56 -06:00
|
|
|
const purgeForTailwind = content => content.match(/[\w-/:]+(?<!:)/g) || [];
|
2018-02-08 23:15:15 -06:00
|
|
|
|
2018-12-16 15:27:09 -06:00
|
|
|
task("buildJekyll", () => {
|
2018-11-06 11:57:51 -05:00
|
|
|
browserSync.notify("Building Jekyll site...");
|
2018-12-16 15:27:09 -06:00
|
|
|
|
2020-01-25 12:40:26 -06:00
|
|
|
const args = ["exec", jekyll, "build"];
|
2018-11-06 11:57:51 -05:00
|
|
|
|
2020-01-25 12:08:59 -06:00
|
|
|
if (isDevelopmentBuild) {
|
2018-12-16 15:27:09 -06:00
|
|
|
args.push("--incremental");
|
|
|
|
}
|
2018-11-06 11:57:51 -05:00
|
|
|
|
|
|
|
return spawn("bundle", args, { stdio: "inherit" });
|
|
|
|
});
|
|
|
|
|
2020-01-25 12:08:59 -06:00
|
|
|
task("processStyles", () => {
|
2018-12-16 15:27:09 -06:00
|
|
|
browserSync.notify("Compiling styles...");
|
2018-11-06 11:57:51 -05:00
|
|
|
|
2020-01-25 12:08:59 -06:00
|
|
|
return src(PRE_BUILD_STYLESHEET)
|
2018-12-16 15:27:09 -06:00
|
|
|
.pipe(
|
2020-01-25 12:35:18 -06:00
|
|
|
postcss([
|
|
|
|
atimport(),
|
|
|
|
tailwindcss(TAILWIND_CONFIG),
|
|
|
|
...(!isDevelopmentBuild
|
|
|
|
? [
|
|
|
|
purgecss({
|
2020-01-26 00:09:21 -06:00
|
|
|
content: [`${SITE_ROOT}/**/*.html`],
|
2020-01-26 00:07:31 -06:00
|
|
|
defaultExtractor: content =>
|
|
|
|
content.match(/[\w-/:]+(?<!:)/g) || []
|
2020-01-25 12:35:18 -06:00
|
|
|
}),
|
|
|
|
autoprefixer(),
|
|
|
|
cssnano()
|
|
|
|
]
|
|
|
|
: [])
|
|
|
|
])
|
2018-12-16 15:27:09 -06:00
|
|
|
)
|
2020-01-25 12:08:59 -06:00
|
|
|
.pipe(dest(POST_BUILD_STYLESHEET));
|
2018-12-16 15:27:09 -06:00
|
|
|
});
|
2018-11-06 11:57:51 -05:00
|
|
|
|
2018-12-16 15:27:09 -06:00
|
|
|
task("startServer", () => {
|
2017-11-08 20:34:49 -06:00
|
|
|
browserSync.init({
|
2020-01-25 12:08:59 -06:00
|
|
|
files: [SITE_ROOT + "/**"],
|
2017-11-20 19:24:25 -06:00
|
|
|
open: "local",
|
2018-02-08 23:15:15 -06:00
|
|
|
port: 4000,
|
2017-11-08 20:34:49 -06:00
|
|
|
server: {
|
2020-01-25 12:08:59 -06:00
|
|
|
baseDir: SITE_ROOT,
|
2019-04-07 19:39:55 +02:00
|
|
|
serveStaticOptions: {
|
|
|
|
extensions: ["html"]
|
|
|
|
}
|
2017-11-08 20:34:49 -06:00
|
|
|
}
|
|
|
|
});
|
2017-11-11 02:26:29 -06:00
|
|
|
|
2018-11-06 11:57:51 -05:00
|
|
|
watch(
|
2018-02-12 20:37:11 -06:00
|
|
|
[
|
2019-07-16 22:48:16 -05:00
|
|
|
"**/*.css",
|
|
|
|
"**/*.html",
|
|
|
|
"**/*.js",
|
2018-02-12 20:37:11 -06:00
|
|
|
"**/*.md",
|
2019-05-16 23:58:35 +02:00
|
|
|
"**/*.markdown",
|
2019-07-16 22:45:00 -05:00
|
|
|
"!_site/**/*",
|
2019-07-16 22:48:16 -05:00
|
|
|
"!node_modules/**/*"
|
2018-12-16 15:27:09 -06:00
|
|
|
],
|
|
|
|
{ interval: 500 },
|
2018-08-09 22:54:58 -05:00
|
|
|
buildSite
|
2018-02-08 23:15:15 -06:00
|
|
|
);
|
2018-11-06 11:57:51 -05:00
|
|
|
});
|
|
|
|
|
2018-12-16 15:27:09 -06:00
|
|
|
const buildSite = series("buildJekyll", "processStyles");
|
2017-11-08 20:34:49 -06:00
|
|
|
|
2018-12-16 15:27:09 -06:00
|
|
|
exports.serve = series(buildSite, "startServer");
|
2018-11-06 11:57:51 -05:00
|
|
|
exports.default = series(buildSite);
|