Purgecss wrapper for Laravel Mix
Purgecss doesn't require too much work to set up, but there's some boilerplate involved. This package adds a
purgeCss method to Laravel Mix, which installs Purgecss for you with a set of sensible defaults. Zero configuration for your average Laravel project!
let mix = ;;// ...mix;
The Purgecss config is inspired by Jonathan Reinink's config for Tailwind CSS.
Before you get started, make sure you're using
laravel-mix version 2.1 or higher.
For version 2.0.* of
laravel-mixplease use version 1.* of this wrapper. This wrapper is not compatible with
You can install the package with yarn or npm:
yarn add laravel-mix-purgecss
npm install laravel-mix-purgecss
Then install the extension by requiring the module in your Mix configuration.
let mix = ;;// ...
Purgecss can then be enabled by calling
.purgeCss() in your Mix chain.
Custom options can be passed when calling Purgecss if necessary.
The default configuration should be good enough for an average Laravel project. In short, all html, js, php & vue files in the app and resources folders will be scanned for selectors. Purgecss is only enabled in production.
||Determines whether css should be purged or not|
||Array||Matches all php files in
||Determines which files should be scanned for selectors|
||Array||resources||Determines which folders should be scanned for selectors|
||Array||html, js, jsx, ts, tsx, php, vue||Determines which file types should be scanned for selectors. If you override
||Regex pattern used to match classes found in the given files.|
Example custom configuration
let mix = ;;mix;
Your custom globs are merged with the default globs. If you need to fully replace the globs, use the underlying
paths option instead.
let mix = ;const glob = ;;mix;
Usage outside of Laravel
Using Laravel Mix outside of a Laravel project? We've got you covered! Everything still works, but you might want to update the folders that are being scanned for selectors.
Laravel stores views and other assets in the
resources folder, so that's where we assume you're keeping things. If you're in a different environment, like Jigsaw, you'll need to update the
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email firstname.lastname@example.org instead of using the issue tracker.
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
The MIT License (MIT). Please see License File for more information.