Install Yahoo YUI compressor on Mac OS X, use in terminal

Since there are seemingly no simple guides on how to simply install the YUI compressor on Mac, or how to use it in the terminal (command line) as Yahoo’s instructions are useless, and most other guides show how to use it integrated into a website as an on-the-fly processor; if you’d prefer to compress your assets prior to deployment as opposed to on-the-fly then you’ll need to get YUI working in the terminal so you can use it in a bash script or something similar.

You could get the latest release from GitHub and then have no idea what to do… or just install it via Homebrew, which will fetch, build and install it for you

brew install yuicompressor

You should then be able to just run yuicompressor from the terminal, which will minify 1 or more files you pass as parameters and output them to ther screen. If you want to save these to a file, just pass the output to a file as you would normally

yuicompressor test.css > test.min.css
yuicompressor test.js > test.min.js