Skip to content

Instantly share code, notes, and snippets.

@SaneMethod
Created May 28, 2013 19:52
Show Gist options
  • Save SaneMethod/5665589 to your computer and use it in GitHub Desktop.
Save SaneMethod/5665589 to your computer and use it in GitHub Desktop.
Minify javascript and css using Google closure compiler and closure stylesheets.
#!/bin/sh
#set defaults
ini=build.ini
csspath=../static/css/
jspath=../static/js/
jsout=../static/js/compiled.js
cssout=../static/css/compiled.css
js=
css=
#Get arguments and set vars appropriately
while [ "$1" != "" ]
do
if [ "$1" = "--help" ]
then
echo --Usage--
echo build -j "path/to/java" -i "path/to/ini" --jspath "path/to/js/files" --csspath "path/to/css/files" --jsout "path/to/js/output.js" --cssout "path/to/css/output.css"
echo --Params--
echo Note: All parameters are optional
echo -j Specify path to java, where 'bin' directory resides
echo -i Specfiy path and filename of ini file default build.ini
echo --jspath Specify path to the js files whose names are defined in the ini file
echo --csspath As above, for css files
echo --jsout Specify output path and filename for the compiled js file
echo --cssout As above, for css
exit 0
elif [ "$1" = "-i" ]
then
ini=$2
elif [ "$1" = "-j" ]
then
java_home=$2
elif [ "$1" = "--jspath" ]
then
jspath=$2
elif [ "$1" = "--csspath" ]
then
csspath=$2
elif [ "$1" = "--jsout" ]
then
jsout=$2
elif [ "$1" = "--cssout" ]
then
cssout=$2
fi
shift
shift
done
#Read in paths from specified ini file
OIFS=$IFS
IFS="="
while read LINE
do
set $LINE
if [ "$1" = "js" ]
then
js="$js --js=$jspath$2"
elif [ "$1" = "css" ]
then
css="$css $csspath$2"
fi
done < $ini
IFS=$OIFS
#Remove leading spaces
js=`echo $js|sed 's/^ *//g'`
css=`echo $css|sed 's/^ *//g'`
#Perform compilation
java -jar compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS $js --js_output_file=$jsout
java -jar compiler_css.jar --allow-unrecognized-functions $css -o $cssout
@vbresan
Copy link

vbresan commented Mar 28, 2021

I know that years have gone, but what is compiler_css.jar and where did you get it from?

@SaneMethod
Copy link
Author

That was the Google Closure Stylesheet tool. See this post for more details: https://artandlogic.com/2013/05/minification-smaller-quicker-is-better/

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