vac.dev-experimental-old/gulpfile.babel.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

import autoprefixer from "autoprefixer";
import browserSync from "browser-sync";
import spawn from "cross-spawn";
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";
2021-08-05 15:27:46 +00:00
import imagemin from "gulp-imagemin";
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/`;
2021-08-05 14:52:53 +00:00
const PRE_BUILD_STYLESHEET = "./assets/css/style.css";
2021-08-05 15:27:46 +00:00
const IMAGES = "./assets/img";
const IMAGES_MINIMIZED = `${SITE_ROOT}/assets/`;
2020-01-25 18:08:59 +00:00
const TAILWIND_CONFIG = "./tailwind.config.js";
2017-11-21 01:37:43 +00:00
// Fix for Windows compatibility
const jekyll = process.platform === "win32" ? "jekyll.bat" : "jekyll";
2017-11-09 02:34:49 +00:00
const isDevelopmentBuild = process.env.NODE_ENV === "development";
2018-12-16 21:27:09 +00:00
task("buildJekyll", () => {
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"];
2020-01-25 18:08:59 +00:00
if (isDevelopmentBuild) {
2018-12-16 21:27:09 +00:00
args.push("--incremental");
}
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...");
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
});
task("cname", () => {
return src('assets/CNAME').pipe(dest(SITE_ROOT));
});
2021-08-05 15:27:46 +00:00
task("images", () => {
return src(IMAGES)
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo(),
])
)
.pipe(dest(IMAGES_MINIMIZED));
});
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 + "/**"],
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,
serveStaticOptions: {
extensions: ["html"],
},
},
2017-11-09 02:34:49 +00:00
});
watch(
[
2019-07-17 03:48:16 +00:00
"**/*.css",
"**/*.html",
"**/*.js",
"**/*.md",
"**/*.markdown",
2019-07-17 03:45:00 +00:00
"!_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
);
});
const buildSite = series("buildJekyll", "processStyles", "images", "cname");
2017-11-09 02:34:49 +00:00
2018-12-16 21:27:09 +00:00
exports.serve = series(buildSite, "startServer");
exports.default = series(buildSite);