Last active
August 28, 2024 21:30
-
-
Save andrewdelprete/277a5a2af33aea2481c54a6a8b35d6c3 to your computer and use it in GitHub Desktop.
Laravel Mix: Tailwind CSS + PurgeCSS Example
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
let mix = require("laravel-mix"); | |
let tailwindcss = require("tailwindcss"); | |
let glob = require("glob-all"); | |
let PurgecssPlugin = require("purgecss-webpack-plugin"); | |
/** | |
* Custom PurgeCSS Extractor | |
* https://github.com/FullHuman/purgecss | |
* https://github.com/FullHuman/purgecss-webpack-plugin | |
*/ | |
class TailwindExtractor { | |
static extract(content) { | |
return content.match(/[A-z0-9-:\/]+/g); | |
} | |
} | |
mix.postCss("./src/styles.css", "public/css", [tailwindcss("./tailwind.js")]); | |
mix.webpackConfig({ | |
plugins: [ | |
new PurgecssPlugin({ | |
paths: glob.sync([ | |
path.join(__dirname, "resources/views/**/*.blade.php"), | |
path.join(__dirname, "resources/assets/js/**/*.vue") | |
]), | |
extractors: [ | |
{ | |
extractor: TailwindExtractor, | |
extensions: ["html", "js", "php", "vue"] | |
} | |
] | |
}) | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah, thanks a lot!
purgecss together with tailwind is the best thing ever happend! 👍