92 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-02-08 23:15:15 -06:00
const gulp = require("gulp");
const gutil = require("gulp-util");
const child = require("child_process");
const browserSync = require("browser-sync").create();
const siteRoot = "_site";
const mainCSS = "src/style.css"; /* Main stylesheet (pre-build) */
const tailwindConfig = "tailwind.js"; /* Tailwind config */
2017-11-20 19:37:43 -06:00
2018-02-08 23:15:15 -06:00
/**
* Fix Windows compatibility issue
*/
const jekyll = process.platform === "win32" ? "jekyll.bat" : "jekyll";
2017-11-15 13:53:20 +01:00
/**
2017-11-20 19:37:43 -06:00
* Build Jekyll Site
2017-11-15 13:53:20 +01:00
*/
2018-02-08 23:15:15 -06:00
gulp.task("jekyll-build", ["css"], function() {
browserSync.notify("Building Jekyll site...");
return child.spawn(jekyll, ["build"], { stdio: "inherit" });
2017-11-08 20:34:49 -06:00
});
2017-11-15 13:53:20 +01:00
/**
2018-02-08 23:15:15 -06:00
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
*/
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g);
}
}
/**
* Compile CSS
2017-11-15 13:53:20 +01:00
*/
2018-02-08 23:15:15 -06:00
gulp.task("css", function() {
const atimport = require("postcss-import");
const postcss = require("gulp-postcss");
const tailwindcss = require("tailwindcss");
const purgecss = require("gulp-purgecss");
const autoprefixer = require("gulp-autoprefixer");
const cleancss = require("gulp-clean-css");
browserSync.notify("Compiling CSS...");
return gulp
.src(mainCSS)
.pipe(postcss([atimport(), tailwindcss(tailwindConfig)]))
.pipe(
purgecss({
content: ["_site/**/*.html"],
extractors: [
{
extractor: TailwindExtractor,
extensions: ["html", "js"]
}
]
})
)
.pipe(
autoprefixer({
browsers: ["last 2 versions"],
cascade: false
})
)
2017-11-08 20:34:49 -06:00
.pipe(cleancss())
2018-02-08 23:15:15 -06:00
.pipe(gulp.dest("assets/css/"))
.pipe(gulp.dest("_site/assets/css/"));
2017-11-08 20:34:49 -06:00
});
2017-11-15 13:53:20 +01:00
/**
2017-11-22 16:35:50 -06:00
* Serve site with Browsersync
2017-11-15 13:53:20 +01:00
*/
2018-02-08 23:15:15 -06:00
gulp.task("serve", ["jekyll-build"], () => {
2017-11-08 20:34:49 -06:00
browserSync.init({
2018-02-08 23:15:15 -06:00
files: [siteRoot + "/**"],
open: "local",
2018-02-08 23:15:15 -06:00
port: 4000,
2017-11-08 20:34:49 -06:00
server: {
baseDir: siteRoot
}
});
2018-02-08 23:15:15 -06:00
gulp.watch([mainCSS, tailwindConfig], ["css"]);
gulp.watch(
["**/*.html", "**/*.md", "**/*.yml", "!_site/**/*, !node_modules"],
{ interval: 500 },
["jekyll-build"]
);
2017-11-08 20:34:49 -06:00
});
2018-02-08 23:15:15 -06:00
gulp.task("default", ["serve"]);