2018-11-06 16:57:51 +00:00
|
|
|
import autoprefixer from "autoprefixer";
|
|
|
|
import browserSync from "browser-sync";
|
2020-04-05 16:37:58 +00:00
|
|
|
import spawn from "cross-spawn";
|
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-08-10 03:54:58 +00:00
|
|
|
import postcss from "gulp-postcss";
|
2018-12-16 21:27:09 +00:00
|
|
|
import atimport from "postcss-import";
|
2018-08-10 03:54:58 +00:00
|
|
|
import tailwindcss from "tailwindcss";
|
|
|
|
|
2020-01-25 18:08:59 +00: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-21 01:37:43 +00:00
|
|
|
|
2018-11-06 16:57:51 +00:00
|
|
|
// Fix for Windows compatibility
|
2020-04-05 16:37:58 +00:00
|
|
|
const jekyll = process.platform === "win32" ? "jekyll.bat" : "jekyll";
|
2017-11-09 02:34:49 +00:00
|
|
|
|
2020-01-25 18:45:15 +00:00
|
|
|
const isDevelopmentBuild = process.env.NODE_ENV === "development";
|
|
|
|
|
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
|
|
|
|
2020-01-25 18:40:26 +00:00
|
|
|
const args = ["exec", jekyll, "build"];
|
2018-11-06 16:57:51 +00:00
|
|
|
|
2020-01-25 18:08:59 +00:00
|
|
|
if (isDevelopmentBuild) {
|
2018-12-16 21:27:09 +00:00
|
|
|
args.push("--incremental");
|
|
|
|
}
|
2018-11-06 16:57:51 +00:00
|
|
|
|
|
|
|
return spawn("bundle", args, { stdio: "inherit" });
|
|
|
|
});
|
|
|
|
|
2020-01-25 18:08:59 +00:00
|
|
|
task("processStyles", () => {
|
2018-12-16 21:27:09 +00:00
|
|
|
browserSync.notify("Compiling styles...");
|
2018-11-06 16:57:51 +00:00
|
|
|
|
2020-01-25 18:08:59 +00:00
|
|
|
return src(PRE_BUILD_STYLESHEET)
|
2018-12-16 21:27:09 +00:00
|
|
|
.pipe(
|
2020-01-25 18:35:18 +00:00
|
|
|
postcss([
|
|
|
|
atimport(),
|
|
|
|
tailwindcss(TAILWIND_CONFIG),
|
2020-05-02 00:09:13 +00:00
|
|
|
...(isDevelopmentBuild ? [] : [autoprefixer(), cssnano()]),
|
2020-01-25 18:35:18 +00:00
|
|
|
])
|
2018-12-16 21:27:09 +00:00
|
|
|
)
|
2020-01-25 18:08:59 +00:00
|
|
|
.pipe(dest(POST_BUILD_STYLESHEET));
|
2018-12-16 21:27:09 +00:00
|
|
|
});
|
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({
|
2020-01-25 18:08:59 +00:00
|
|
|
files: [SITE_ROOT + "/**"],
|
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: {
|
2020-01-25 18:08:59 +00:00
|
|
|
baseDir: SITE_ROOT,
|
2019-04-07 17:39:55 +00:00
|
|
|
serveStaticOptions: {
|
2020-04-05 16:37:58 +00:00
|
|
|
extensions: ["html"],
|
|
|
|
},
|
|
|
|
},
|
2017-11-09 02:34:49 +00:00
|
|
|
});
|
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-07-17 03:48:16 +00:00
|
|
|
"**/*.css",
|
|
|
|
"**/*.html",
|
|
|
|
"**/*.js",
|
2018-02-13 02:37:11 +00:00
|
|
|
"**/*.md",
|
2019-05-16 21:58:35 +00:00
|
|
|
"**/*.markdown",
|
2019-07-17 03:45:00 +00:00
|
|
|
"!_site/**/*",
|
2020-04-05 16:37:58 +00:00
|
|
|
"!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);
|