Skip to content

Instantly share code, notes, and snippets.

@andrewdelprete
Last active July 17, 2020 09:26
Show Gist options
  • Save andrewdelprete/277a5a2af33aea2481c54a6a8b35d6c3 to your computer and use it in GitHub Desktop.
Save andrewdelprete/277a5a2af33aea2481c54a6a8b35d6c3 to your computer and use it in GitHub Desktop.
Laravel Mix: Tailwind CSS + PurgeCSS Example
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"]
}
]
})
]
});
@ockam
Copy link

ockam commented Nov 27, 2017

@andrewdelprete

I did some testing with your idea and it doesn’t appear to work. :(

There is an issue opened on Laravel Mix about purgecss. I cross my finger and hope something can come out of it.

@andrewdelprete
Copy link
Author

andrewdelprete commented Nov 27, 2017

@ockam - Gotcha! that makes sense. I posted a comment there! That particular issue has to do with him not running his css through Webpack and is just combining together with Mix.combine().

@simonhamp
Copy link

This is brilliant @andrewdelprete. Thanks! 👍

@cyberEst1919
Copy link

yeah, thanks a lot!
purgecss together with tailwind is the best thing ever happend! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment