Skip to content

Instantly share code, notes, and snippets.

@astrotars
Created September 24, 2012 15:54
Show Gist options
  • Save astrotars/3776682 to your computer and use it in GitHub Desktop.
Save astrotars/3776682 to your computer and use it in GitHub Desktop.
JS and CSS compression using yuicompressor
#!/bin/sh
#
#current directory
#
DIR=$PWD;
#
#concatenate all javascript files and compress
#using yuicompressor. output as min.js.
#
echo "# Compressing Javascript and CSS."
#directory for the JS files
JS_DIR=$DIR/public/scripts/views
#paths to final combined and minified files
JS_MIN_FILE=$JS_DIR/min.js
#remove existing js min file
rm -rf $JS_DIR/min.js
#concatenate all js files
cat $JS_DIR/*.js > $JS_MIN_FILE
#compress using yui compressor and output into js directory
yuicompressor $JS_MIN_FILE --type js -o $JS_MIN_FILE
#add the file to the git base
git add $JS_MIN_FILE
#
#loop through each less file and convert to css,
#and compress css using yuicompressor.
#
#directory for the CSS files
CSS_DIR=$DIR/public/css
#for each less file
for F in $CSS_DIR/*.less; do
#compile less to css
lessc "$F" > "$F".css
done
#for each css file
for F in $CSS_DIR/*.css; do
#compress using yuicompressor
yuicompressor "$F" --type css -o "$F"
#add the file to the git base
git add "$F"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment