๐ Laravel CSS Optimizer: Purge unused CSS, Minify styles, Boost website speed & SEO. Zero-config setup for Tailwind, Bootstrap. 30%+ smaller CSS files guaranteed.
deshithemes/css-cleaner is a Laravel package for ๐ laravel css optimizer: purge unused css, minify styles, boost website speed & seo. zero-config setup for tailwind, bootstrap. 30%+ smaller css files guaranteed..
It currently has 1 GitHub stars and 9 downloads on Packagist (latest version v1.1.0).
Install it with composer require deshithemes/css-cleaner.
Discover more Laravel packages by deshithemes
or browse all Laravel packages to compare alternatives.
Last updated
๐ฅ Laravel package to automatically purge and minify CSS files in the public directory. Clean, optimized, and beginner-friendly with powerful Artisan commands. Made by Ruman ๐ช
Remove Unused CSS โข Minify โข Optimize โ All in One for Laravel
Created with ๐ by Ruman
Laravel CSS Cleaner is a developer-friendly Laravel package that:
โ
Removes unused CSS
โ
Minifies your styles
โ
Optimizes Laravelโs public CSS automatically
โ
Works with Tailwind, Bootstrap, or custom styles
โ
Requires zero manual searching for dead styles!
/public directory for .css files/public/css/optimized/ foldermodal, fade, active, etc.| Feature | Icon | Description | |---------|------|-------------| | Auto Purge | ๐งน | Removes unused CSS classes | | Smart Minification | โจ | Compresses CSS files | | Safelist Protection | ๐ก๏ธ | Preserves dynamic classes | | Zero Config | ๐ฏ | Works out-of-the-box | | Progress Tracking | ๐ | Real-time optimization stats |
composer require DeshiThemes/css-cleaner
Publish the config file:
php artisan vendor:publish --tag=css-cleaner-config
or, if not working or not genarating file under config/csscleaner.php then run command (optional)
php artisan vendor:publish --tag=css-cleaner-config --force
Install the required Node.js dependency:
npm install @fullhuman/postcss-purgecss --save-dev
โ๏ธ Configuration
The configuration file will be published to: config/csscleaner.php
return [
/**
* ๐ CSS Source Directory
*
* Tip: For better performance, specify exact subdirectory when possible:
* 'css_path' => public_path('css'),
*/
'css_path' => public_path(),
/**
* ๐ Output Directory
*
* Important: Directory will be created automatically
* but parent directory must exist!
*/
'output_path' => public_path('css/optimized'),
/**
* ๐ Content Files to Scan
*
* Pro Tip: Add all file types that might contain CSS class names:
* - Blade templates
* - JavaScript components
* - Markdown files (if using)
*/
'content_paths' => [
'resources/views/**/*.blade.php',
'resources/js/**/*.vue',
// 'storage/framework/views/*.php' // Uncomment for cached views
],
/**
* ๐ก๏ธ Safelist Configuration
*
* Formats:
* - Exact: 'active'
* - Wildcard: 'modal-*'
* - Regex: '/^tooltip/'
*
* Always include:
* - JS-toggled classes
* - Animation classes
* - Dynamically generated classes
*/
'safelist' => [
// Core classes
'active', 'show', 'collapse',
// Bootstrap specific
'modal', 'fade', 'collapsing',
'/^carousel/', '/^tooltip/', '/^bs-tooltip/',
// Add your project-specific classes here
],
/**
* โ๏ธ PurgeCSS Options
*
* Recommendation: Keep keyframes and fontFace
* unless you're manually handling them
*/
'purge_options' => [
'keyframes' => true, // Keep @keyframes
'fontFace' => true, // Keep @font-face
'variables' => false, // Remove unused CSS variables
'rejected' => false // Don't log removed selectors
],
/**
* โ๏ธ Minification Options
*
* Warning: preserve_license=false will remove all comments
* including legal/license blocks!
*/
'minify_options' => [
'remove_comments' => true, // Remove all comments
'preserve_license' => false, // Remove even license comments
'advanced' => true // Enable advanced optimizations
]
];
You can customize which classes to always keep and where output should go.
๐งฉ Command ๐ก Description โ Usage Example
๐งผ css:purge Purges unused CSS from all files in /public php artisan css:purge โ๏ธ css:minify Minifies the cleaned CSS files php artisan css:minify ๐ css:optimize Runs both purge + minify together php artisan css:optimize
๐งช Beginner-Friendly Usage ๐งผ Purge Only
php artisan css:purge
๐งน This removes unused CSS classes from .css files and puts them in:
/public/css/cleaned/
โ๏ธ Minify Only
php artisan css:minify
๐ฏ After purging, use this to compress styles โ whitespace and comments are removed.
๐ Optimize (Purge + Minify)
php artisan css:optimize
๐ฅ Best option for production โ a full clean-up + compression in one step.
๐ Example: Input vs Output Input Files:
public/css/style.css
public/assets/vendor/bootstrap.css
After css:optimize, Output:
public/css/cleaned/css/style.css
public/css/cleaned/assets/vendor/bootstrap.css
โ Folder structure is preserved โ Only used classes remain โ Files are compressed
| Command | Icon | Description | Example |
|---------|------|-------------|---------|
| php artisan css:purge | ๐งน | Remove unused CSS | php artisan css:purge --safelist="active,modal-*" |
| php artisan css:minify | โจ | Minify CSS files | php artisan css:minify --path=public/css |
| php artisan css:optimize | ๐ | Purge + Minify together | php artisan css:optimize --stats |
| Command | Icon | Description | Example |
|---------|------|-------------|---------|
| css-cleaner purge | ๐๐งน | Global purge | css-cleaner purge --path=/var/www/project |
| css-cleaner minify | ๐โจ | Global minify | css-cleaner minify --output=dist |
| css-cleaner optimize | ๐๐ | Global optimization | css-cleaner optimize --verbose |
php artisan css:purge
php artisan css:optimize --stats
php artisan css:minify --path=public/css
php artisan css:purge --safelist="active,show"
php artisan css:optimize --css-path=public/assets --output=public/dist
php artisan css:purge --safelist="active,modal-*,/^tooltip/"
name: Optimize CSS
run: |
php artisan css:optimize
git add public/css/cleaned
git commit -m "Optimized CSS"
php artisan css:purge --dry-run
--verbose:css-cleaner optimize --verbose
php artisan css:optimize --keep-structure
| Situation | Icon | Benefit | |-----------|------|---------| | Before Production | ๐ | Boost performance by 50-90% | | Bootstrap/Tailwind Sites | ๐งน | Remove 80-95% unused CSS | | Portfolio/Business Sites | โก | Faster loading pages | | After View Updates | ๐ | Keep CSS lean | | CI/CD Pipelines | ๐ค | Automate optimization |
--safelist="show,collapse,fade"
php artisan css:optimize
# forge.sh or github-actions.yml
| Technology | Icon | Version | Highlight |
|------------|------|---------|-----------|
| PHP | ๐ | 8.1 - 8.4 | โ Fully Supported |
| Laravel | ๐ฏ | 10.x - 12.x | โ Optimized |
| Bootstrap | ๐
ฑ๏ธ | 4.x - 5.x | โ ๏ธ v3 needs config |
| Tailwind | ๐ช๏ธ | All versions | โ Perfect match |
| Laravel Mix | ๐จ | v6+ | โ Works great |
| Vite | โก | v3+ | โ Post-build only |
| Custom CSS | โจ | Any .css | โ Universal |
php -v # Requires 8.1+
composer show laravel/framework # Requires 10+
node -v # Requires 16+
| Project Type | Benefit of Using This Package | | ------------------------ | ---------------------------------- | | ๐ eCommerce (Bootstrap) | Smaller styles, faster checkout UX | | ๐ LMS Site (Tailwind) | Less bloat, faster page loads | | ๐งโ๐จ Portfolio | Light footprint for static sites | | ๐ข Business Website | Quick, optimized performance | | ๐ Admin Panel | Clean dashboard assets |
| Scenario | Original Size | Optimized Size | Reduction | |------------------|------------------:|-------------------:|--------------:| | Bootstrap 5 | 187 KB | 24 KB | 87% | | Tailwind | 1.2 MB | 28 KB | 98% |
composer global require deshithemes/css-cleaner
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc
css-cleaner --version
Optimize any project
css-cleaner optimize --path=/var/www/project/public
# Minify specific directory
css-cleaner minify --path=./public/css
sudo chown -R $USER:$USER ~/.composer/
composer global bin deshithemes/css-cleaner install
# Use full path to composer binaries
php C:\Users\You\AppData\Roaming\Composer\vendor\bin\css-cleaner optimize
โจ Crafted with โค๏ธ by Ruman
```