minify/README.md

54 lines
2.2 KiB
Markdown
Raw Normal View History

2012-10-09 12:48:24 +02:00
# Minify
2012-10-09 02:29:59 -07:00
2014-10-08 17:03:29 +02:00
[![Build status](https://api.travis-ci.org/matthiasmullie/minify.svg?branch=master)](https://travis-ci.org/matthiasmullie/minify)
[![Latest version](http://img.shields.io/packagist/v/matthiasmullie/minify.svg)](https://packagist.org/packages/matthiasmullie/minify)
[![Downloads total](http://img.shields.io/packagist/dt/matthiasmullie/minify.svg)](https://packagist.org/packages/matthiasmullie/minify)
[![License](http://img.shields.io/packagist/l/matthiasmullie/minify.svg)](https://github.com/matthiasmullie/minify/blob/master/LICENSE)
2012-10-09 12:48:24 +02:00
## 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);
2012-10-09 12:48:24 +02:00
### add($path, /* overload paths */)
This is roughly equivalent to the constructor.
$minifier->add($path3);
$minifier->add($css);
### minify($path)
2012-10-09 12:48:24 +02:00
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');
2012-10-09 12:48:24 +02:00
## 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);
2012-10-09 12:48:24 +02:00
// 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');
2012-10-09 12:48:24 +02:00
## License
2013-04-15 15:09:28 +03:00
Minify is [MIT](http://opensource.org/licenses/MIT) licensed.
2013-12-26 16:03:20 +01:00
## CLI script
[Baki Goxhaj](https://github.com/banago) developed a [CLI tool](https://github.com/banago/CLI-Minify) using this library - could be useful to automate minification of your project's CSS/JS files in e.g. some build or deployment script.