Forked from taylorbryant/purgecss-tailwind-gulp-example.js
Created
September 10, 2018 14:32
-
-
Save philipboomy/f45c8d7fc746d6c619d268578a94ac36 to your computer and use it in GitHub Desktop.
Use PurgeCSS with Tailwind & Gulp (Inspired by @andrewdelprete)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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