Minify

Build status Latest version Downloads total License

Methods

Available methods, for both CSS & JS minifier, are:

__construct(/* overload paths */)

The object constructor accepts 0, 1 or multiple paths of files, or even complete CSS content, that should be minified. All CSS passed along, will be combined into 1 minified file.

use MatthiasMullie\Minify;
$minifier = new Minify\CSS($path1, $path2);

add($path, /* overload paths */)

This is roughly equivalent to the constructor.

$minifier->add($path3);
$minifier->add($css);

minify($path)

This will minify the files' content, save the result to $path and return the resulting content. If the $path parameter is false, the result will not be written anywhere. CAUTION: Only use this for "simple" CSS: if no target directory ($path) is known, relative uris to e.g. images can not be fixed!

$minifier->minify('/target/path.css');

Example usage

$file1 = '/path/to/file1.css';
$file2 = '/yet/another/path/to/file2.css';
$file3 = '/and/another/path/to/file3.css';
$css = 'body { color: #000000; }';

// constructor can be overloaded with multiple files
$minifier = new Minify\CSS($file1, $file2);

// or files can be added individually
$minifier->add($file3);

// or even css content can be loaded
$minifier->add($css);

// minify & write to file
$minifier->minify('/target/path.css');

License

Minify is MIT licensed.

CLI script

Baki Goxhaj developed a CLI tool using this library - could be useful to automate minification of your project's CSS/JS files in e.g. some build or deployment script.

Description
No description provided
Readme MIT 7.8 MiB
Languages
PHP 86.8%
JavaScript 11.5%
CSS 0.8%
Makefile 0.6%
Dockerfile 0.3%