Join 25,000+ Laravel Developers and join the free Laravel Newsletter
A Zero-config Purgecss Wrapper for Laravel Mix
Laravel Packages / January 26, 2018

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.

This appeared first on Laravel News
Laravel News Partners

Newsletter

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