Skip to content

Instantly share code, notes, and snippets.

@jonhoo
Created February 6, 2013 12:36
Show Gist options
  • Save jonhoo/4722294 to your computer and use it in GitHub Desktop.
Save jonhoo/4722294 to your computer and use it in GitHub Desktop.
A very minimal CSS minifier
#!/bin/bash
cat $1 \
| tr '\r\n' ' ' \
| perl -pe 's:/\*.*?\*/::g' \
| sed \
-e 's/\s\+/ /g' \
-e 's/\([#\.:]\)\s\?/\1/g' \
-e 's/\s\?\([;{}]\)\s\?/\1/g' \
-e 's/\s\?\([,!+~>]\)\s\?/\1/g' \
-e 's/;}/}/g' \
-e 's/0\(\.[0-9]\)/\1/g' \
-e 's/\(background\|outline\|border\(-left\|-right\|-top\|-bottom\)\?\):none\b/\1:0/g' \
-e 's/}[^{]\+{}/}/g' \
> $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment