Skip to content

Instantly share code, notes, and snippets.

@michaelaguiar
Forked from fideloper/minify.sh
Last active October 3, 2015 02:28
Show Gist options
  • Save michaelaguiar/2372430 to your computer and use it in GitHub Desktop.
Save michaelaguiar/2372430 to your computer and use it in GitHub Desktop.
Minify with YUI shell script
# src: http://www.craig-russell.co.uk/bulk-minify-shell-script/
CSS='css'
JS='js'
FILELIST="minify.$$.tmp"
COMPORESSOR="yuicompressor-2.4.2.jar"
MINCSS="css/styles.min.css"
# Minify CSS to single file
echo -n '' > $MINCSS
ls $CSS | grep -v min > $FILELIST
while read LINE
do
OLD="$CSS/$LINE"
echo "$OLD -> $MINCSS"
java -jar yuicompressor-2.4.2.jar $OLD >> $MINCSS #bug fix: fix media queries
done < $FILELIST
# Minify JS to multiple files
ls $JS | grep -v min > $FILELIST
while read LINE
do
OLD="$JS/$LINE"
NEW=` echo "$JS/$LINE" | sed 's/\.js/.min.js/g'`
echo "$OLD -> $NEW"
java -jar yuicompressor-2.4.2.jar $OLD > $NEW
done < $FILELIST
rm -f $FILELIST
@OlivierCuyp
Copy link

You might want to protect the dot in your sed like this :

sed 's/\.js/.min.js/g'

to avoid mainjs.js >> mainmin.js.min.js

cheers

@michaelaguiar
Copy link
Author

Ah thanks! Didn't even know you commented until now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment