A Zero-config Purgecss Wrapper for Laravel Mix

A Zero-config Purgecss Wrapper for Laravel Mix

Sebastian De Deyne over at Spatie is working on a Purgecss package for Laravel Mix. The package provides zero-config Purgecss for your average Laravel project:

let mix = require('laravel-mix');
require('laravel-mix-purgecss')();

// ...

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .purgeCss();

All HTML, JS, PHP, and Vue files in the app and resource folders get scanned for selectors, and Purgecss is only enabled in production.

Most project shouldn’t need it, but if you need to go beyond the basics, you can configure Purgecss options and three options provided by the laravel-mix-purgecss package:

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .purgeCss({ /* My options */ });

Check the readme for more information on how to configure Purgecss and the additional custom options this package provides Laravel Mix.

If you are not familiar with Purgecss:

Purgecss is a tool to remove unused CSS. It can be used as part of your development workflow. Purgecss comes with a JavaScript API, a CLI, and plugins for popular build tools.

This package gives you Purgecss for free on your Laravel projects, so you can install it and benefit from smaller CSS files in production. Boom!

Check the package out at spatie/laravel-mix-purgecss on GitHub.


Filed in: Laravel Packages


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior PHP/Laravel Developer: Your Dream Work Environment
Remote
iPhone Photography School
In-house Laravel Developer.
Gold Coast / Australia
MXstore
Laravel Developer
Oak Brook, IL
Tidal Commerce
Senior Backend Engineer
Santa Monica only
Saatchi Art
Senior Laravel Developer
San Francisco
Stitch Labs
Senior Software Developer
South Jordan, UT
Lendio
Full-Stack Developer
Paris, France
Wingly