Skip to content

Instantly share code, notes, and snippets.

@mattbierner
Created October 30, 2012 22:54
Show Gist options
  • Save mattbierner/3983634 to your computer and use it in GitHub Desktop.
Save mattbierner/3983634 to your computer and use it in GitHub Desktop.
Closure Compiler Git pre-commit Hook
#!/bin/sh
# Minify js files
COMPILER="java -jar compiler.jar"
OPTIONS="--compilation_level=ADVANCED_OPTIMIZATIONS"
SRC=lib
DEST=dist
function _minify {
local file=$1
local path=${file##*/}
local out="$DEST/${path%.js}.min.js"
echo "Compiling '$file' to '$out'"
$COMPILER $OPTIONS --js=$file --js_output_file=$out
echo "gzip size: $(gzip -c $out | wc -c) bytes"
git add $out
}
for file in $(git diff --cached --name-only --diff-filter=ACM)
do
if [[ $file =~ $SRC/.+\.js ]];
then
_minify $file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment