Configuring Django Pipeline by using Closure compiler for JavaScript files and YUI compressor for CSS

A couple of days ago I lost several hours trying to understand how to configure django-pipeline by replacing UglifyJS (the standard compressor library adopted) with Closure compiler and YUI compressor, which are in my opinion the two best tools to minify JavaScript and CSS respectively.
Fortunately Pipeline is pretty flexible and allows us to choose among different compressors and also write our own compressor, but I had to face some aspects that were initially unclear to me:

1. Understand how executable compressor bins are invoked by Pipeline:

In the documentation they say that you have to specify the absolute path to the bin of the compressor you are going to use… but, while UglifyJS ships with an executable bin, other compressors are usually simple jar files (with no bin), so pointing to that jars won’t work… so what? You have to write an executable yourself! But don’t panic it’s just a matter of writing a single line of bash script and make it executable :)
Let’s considering for example to adopt YUI compressor for CSS:
once downloaded the jar to a know directory in our filesystem, we can create a simple bin which will be used by pipeline by writing the following script:

java -jar "$TOOLS_PATH/yui_compressor-2.4.jar" $@

The script invokes the jar (java -jar) by passing all the arguments received from Pipeline (“$@” is the alien way for bash to accept a variable number of arguments… something like *args in Python).
$TOOLS_PATH is an environment variable I defined that contains the path to the jars directory (in order to avoid hard-coding it in the settings file).
After saving the script as “yui_compressor” (or whatever you like) you need to make it executable:

chmod +x yui_compressor

That’s all! Now we can define our CSS compression preferences in this way (in “” or whatever is your setting file… yes, if you didn’t know you can and should use multiple settings files in order to differentiate settings based on the environment you are running on… but this is another story for another post):

PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
PIPELINE_YUI_BINARY = os.path.join(

(getEnvironmentVariable() is a custom helper I wrote to retrieve environemnt variables)

2. Make Closure compiler do its job without raising exceptions using AngularJS and other “sophisticated” JavaScript stuff

One of the good parts of Closure is that it has a lot of configurable options and specifically in order to make it happy while compiling my stuff I had to set “language_in” to ECMASCRIPT5 and “warning_level” to QUIET (according to the Google documentation and what I found on StackOverflow).
In order to pass these settings Pipeline provides an arguments option for each specific compiler, so I added:

PIPELINE_CLOSURE_ARGUMENTS = '--language_in=ECMASCRIPT5 --warning_level=QUIET'

If you don’t want to use “PIPELINE_CLOSURE_ARGUMENTS” you can also hard-code that flags in the exacutable you wrote, for example:

java -jar "$TOOLS_PATH/closure_compiler-20130823.jar --language_in=ECMASCRIPT5 --warning_level=QUIET " $@

But don’t do that!

End of post… happy compression at all!