Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philipboomy/f45c8d7fc746d6c619d268578a94ac36 to your computer and use it in GitHub Desktop.
Save philipboomy/f45c8d7fc746d6c619d268578a94ac36 to your computer and use it in GitHub Desktop.
Use PurgeCSS with Tailwind & Gulp (Inspired by @andrewdelprete)
const gulp = require('gulp');
const tailwindConfig = "tailwind.js"; /* Path to Tailwind config */
const mainCSS = "src/style.css"; /* Path to main stylesheet */
/**
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
*/
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g);
}
}
gulp.task("css", function() {
const atimport = require("postcss-import");
const postcss = require("gulp-postcss");
const tailwindcss = require("tailwindcss");
const purgecss = require("gulp-purgecss");
return gulp
.src(mainCSS)
.pipe(postcss([atimport(), tailwindcss(tailwindConfig)]))
.pipe(
purgecss({
content: ["**/*.html"],
extractors: [
{
extractor: TailwindExtractor,
extensions: ["html"]
}
]
})
)
.pipe(gulp.dest("build/"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment