thewind1984/css-optimizator

Interface accepts css files and folders / single templates files, then combines provided css files into one, compares it with provided templates, removes unused selectors and minifies final file

1.2.1 2020-05-05 21:45 UTC

This package is auto-updated.

Last update: 2024-12-06 08:10:08 UTC


README

Interface accepts css files and folders / single templates files, then combines provided css files into one, compares it with provided templates, removes unused selectors and minifies final file.
It supports twig templates also, because {% %}, {{ }} and {# #} will be deleted before check.

Latest Stable Version GitHub license

Features

  • Chains of CSS selectors like >, ~
  • Pseudo-classes (with optional sub-selectors)
  • Multiple selectors separated with , (comma)

TODO

  • Parsing of chains of CSS selectors with + separator
    • .class + .subclass
  • Parsing of selectors, which are implemented with quatro brackets
    • audio[controls]
    • [id*="xxx"], [class^="yyy"], [attr$="zzz"]
  • Implementation convertion to xPath for pseudo-classes
    • nth-child
  • Combining of duplicated selectors
    • body {margin; 0;} body {color: #000;} => body {margin: 0; color: #000;}
  • Unification / optimization the rules inside selector
    • margin: 0; margin-bottom: 10px; => margin: 0 0 10px;

Installation through Composer

composer require thewind1984/css-optimizator

Usage

require_once './vendor/autoload.php';
$cssOptimizator = new \CssOptimizator\CssOptimize\CssOptimize();
$cssOptimizator->addCssFile('path/to/assets/file.css');
$cssOptimizator->addSourceFile('path/to/templates/page.html');
$cssOptimizator->optimize()->minify()->saveContent('path/to/assets/file.min.css');