cerdic/css-tidy
CSSTidy is a PHP CSS parser and minifier with full CSS3 support. Optimizes and fixes styles without regex for higher reliability. Includes web UI, core parser class, and a standalone CLI (pcsstidy).
Install via Composer: composer require cerdic/css-tidy. Begin with the minimal workflow: instantiate csstidy, parse a CSS string, and output minified content. Ideal for first use in a Laravel context—e.g., minifying inline <style> blocks in Blade templates or pre-minifying CSS from a CMS before storage. Start by reviewing class.csstidy.php for core API methods (parse(), get_cfg(), print_errors()) and css_optimiser.php (if present) for CLI/web UI patterns. A minimal Laravel service provider or closure example:
$csstidy = new \csstidy();
$csstidy->set_cfg('optimise_shorthands', 1);
$csstidy->parse($unminified_css);
return $csstidy->print->compressed();
php artisan css:minify) that scans public/build/css/*.css, minifies using this package, and overwrites outputs—especially useful when integrating with legacy systems or non-Node asset pipelines.App\Http\Middleware\MinifyInlineStyles, wrap CSS extracted from @style Blade directives (e.g., from rich-text editors) in a request lifecycle hook. Cache the result using Laravel’s cache (e.g., Cache::rememberForever("css-{$hash}", fn() => $minified)) to avoid repeated parsing.optimise_shorthands=2, remove_duplicate_rules=true) Laravel Mix/Vite skips—e.g., preserving !important comments via set_cfg('preserve_critical_comments', true).bin/pcsstidy to pre-minify vendor CSS (e.g., old admin themes) during CI or before deployment, reducing disk I/O vs. runtime parsing.microtime(true); if >5ms per request, cache aggressively.template presets override explicit settings—always test set_cfg('template', 'high') vs. set_cfg('optimise_shorthands', 2) in isolation. Some legacy options (reverse_left_and_right) are ignored in v2+; use get_cfg() to verify active config.$csstidy->print_errors() before output to surface CSS syntax issues (e.g., unclosed brackets) gracefully.CssMinifierService with DI (->bind(CssMinifierInterface::class, fn() => new CssMinifierService())) to enable testability and Laravel caching.bin/pcsstidy for __DIR__ hardcoding issues on Windows; also, some deprecated notices persist in v2.2.0—run tests with -d display_errors=1 during deployment prep.How can I help you explore Laravel packages today?