You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. UglifyCSS is a port of [YUI Compressor](https://github.com/yui/yuicompressor) to [NodeJS](http://nodejs.org) for its CSS part. Its name is a reference to the awesome [UglifyJS](https://github.com/mishoo/UglifyJS) but UglifyCSS is not a CSS parser. Like YUI CSS Compressor, it applies many regexp replacements. Note that a [port to JavaScript](https://github.com/yui/ycssmin) is also available in the YUI Compressor repository.
  2. UglifyCSS passes successfully the test suite of YUI compressor CSS.
  3. Be sure to submit valid CSS to UglifyCSS or you could get weird results.
  4. ### Installation
  5. For a command line usage:
  6. ```sh
  7. $ npm install uglifycss -g
  8. ```
  9. For API usage:
  10. ```sh
  11. $ npm install uglifycss
  12. ```
  13. From Github:
  14. ```sh
  15. $ git clone git://github.com/fmarcia/UglifyCSS.git
  16. ```
  17. ### Command line
  18. ```sh
  19. $ uglifycss [options] [filename] [...] > output
  20. ```
  21. Options:
  22. * `--max-line-len n` adds a newline (approx.) every `n` characters; `0` means no newline and is the default value
  23. * `--expand-vars` expands variables; by default, `@variables` blocks are preserved and `var(x)`s are not expanded
  24. * `--ugly-comments` removes newlines within preserved comments; by default, newlines are preserved
  25. * `--cute-comments` preserves newlines within and around preserved comments
  26. * `--convert-urls d` converts relative urls with the `d` directory as css location
  27. * `--debug` prints full error stack on error
  28. If no file name is specified, input is read from stdin.
  29. ### API
  30. 2 functions are provided:
  31. * `processString( content, options )` to process a given string
  32. * `processFiles( [ filename1, ... ], options )` to process the concatenation of given files
  33. Options are identical to the command line:
  34. * `<int> maxLineLen` for `--max-line-len n`
  35. * `<bool> expandVars` for `--expand-vars`
  36. * `<bool> uglyComments` for `--ugly-comments`
  37. * `<bool> cuteComments` for `--cute-comments`
  38. * `<string> convertUrls` for `--convert-urls d`
  39. * `<bool> debug` for `--debug`
  40. Both functions return uglified css.
  41. #### Example
  42. ```js
  43. var uglifycss = require('uglifycss');
  44. var uglified = uglifycss.processFiles(
  45. [ 'file1', 'file2' ],
  46. { maxLineLen: 500, expandVars: true }
  47. );
  48. console.log(uglified);
  49. ```
  50. ### License
  51. UglifyCSS is MIT licensed.