BBEdit is the pinnacle of text editors for Mac OS; it is the El Supremo in the room at the top of the stairs. I’ve been using it on an almost daily basis for more years than I like to think about, and it just keeps getting better.
To use this, you have to first install the Closure Compiler Java app on your system, which isn’t difficult:
- Download the ZIP file and expand it. (The decompression should happen automatically after downloading; if not, double click the ZIP file.)
- In the Finder’s Go menu, click “Go to Folder…” and enter
/usr/local/libin the dialog box. This opens a desktop window showing that folder.
- Copy the file
compiler.jarfrom the folder
compiler-latestto this new window. Because it’s in a system directory, you’ll probably be asked to enter your login password before the copy will proceed.
That’s it — the Closure Compiler is ready to go. Unless you’ve removed it, Java is already installed in Mac OS, so you shouldn’t need to do anything else.
Now for the Text Filter. In BBEdit, open a new window and and enter this short and simple Bash shell script:
#!/bin/bash echo -n $(java -jar /usr/local/lib/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS <&0)
This script needs to be placed in:
~/Library/Application Support/BBEdit/Text Filters
Easiest way to get it there is to first save it to the Desktop, as
Closure Compiler.sh, then use the Finder’s Go->Go to Folder menu again to open the Text Filters folder, and move the file in. (This time, you shouldn’t need to enter a password because it’s your own Library folder.)
If you mark a selection before using the text filter, just that section will be minified. If you’re feeling adventurous, you can set the compilation_level option in the text filter to “ADVANCED_OPTIMIZATIONS,” but this won’t work with all code; there are some strict requirements. Check the Closure Compiler docs for more on that.