Last active
February 24, 2023 10:30
-
-
Save taylorbryant/91fc05b12472a88a8b6494f610647cd4 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 atimport = require("postcss-import"); | |
const { dest, src, task } = require("gulp"); | |
const postcss = require("gulp-postcss"); | |
const purgecss = require("@fullhuman/postcss-purgecss"); | |
const tailwindcss = require("tailwindcss"); | |
const TAILWIND_CONFIG = "./tailwind.config.js"; | |
const SOURCE_STYLESHEET = "./src/style.css"; | |
const DESTINATION_STYLESHEET = "./build/style.css"; | |
task("css", () => | |
src(SOURCE_STYLESHEET) | |
.pipe( | |
postcss([ | |
atimport(), | |
tailwindcss(TAILWIND_CONFIG), | |
...(process.env.NODE_ENV === "production" | |
? [ | |
purgecss({ | |
content: ["**/*.html"], | |
defaultExtractor: content => | |
content.match(/[\w-/:]+(?<!:)/g) || [] | |
}) | |
] | |
: []) | |
]) | |
) | |
.pipe(dest(DESTINATION_STYLESHEET)) | |
); |
Cool that's works thanks
the best setup on the internet ! not even the library makers could think simple like that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you