UglifyCSS is a port of YUI Compressor to NodeJS for its CSS part. Its name is a reference to the awesome UglifyJS but UglifyCSS is not a CSS parser. Like YUI CSS Compressor, it applies many regexp replacements. Note that a port to JavaScript is also available in the YUI Compressor repository.
UglifyCSS passes successfully the test suite of YUI compressor CSS.
Be sure to submit valid CSS to UglifyCSS or you could get weird results.
For a command line usage:
$ npm install uglifycss -gFor API usage:
$ npm install uglifycssFrom Github:
$ git clone git://github.com/fmarcia/UglifyCSS.git$ uglifycss [options] [filename] [...] > outputOptions:
- --max-line-len nadds a newline (approx.) every- ncharacters;- 0means no newline and is the default value
- --expand-varsexpands variables; by default,- @variablesblocks are preserved and- var(x)s are not expanded
- --ugly-commentsremoves newlines within preserved comments; by default, newlines are preserved
- --cute-commentspreserves newlines within and around preserved comments
- --convert-urls dconverts relative urls using the- ddirectory as location target
- --debugprints full error stack on error
- --output fputs the result in- ffile
If no file name is specified, input is read from stdin.
2 functions are provided:
- processString( content, options )to process a given string
- processFiles( [ filename1, ... ], options )to process the concatenation of given files
Options are identical to the command line:
- <int> maxLineLenfor- --max-line-len n
- <bool> expandVarsfor- --expand-vars
- <bool> uglyCommentsfor- --ugly-comments
- <bool> cuteCommentsfor- --cute-comments
- <string> convertUrlsfor- --convert-urls d
- <bool> debugfor- --debug
Both functions return uglified css.
var uglifycss = require('uglifycss');
var uglified = uglifycss.processFiles(
    [ 'file1', 'file2' ],
    { maxLineLen: 500, expandVars: true }
);
console.log(uglified);UglifyCSS is MIT licensed.