Skip to content

Instantly share code, notes, and snippets.

@kanghyojun
Created July 5, 2012 08:01
Show Gist options
  • Save kanghyojun/3052176 to your computer and use it in GitHub Desktop.
Save kanghyojun/3052176 to your computer and use it in GitHub Desktop.
Minifier

#Minifier on shell script

CSS and JS minifier automation in Directory. you can choose your directory to minify and file type(only css , js)

Basically, your base minifier is a

##Usage

$ ./minifier . js

Or to minifiy css files

$ ./minifier . css

and then you can choose your directory.

$ ./minifier ./some-dir js

##Minifier customize

Change JS_MINIFIER and CSS_MINIFIER whatever you want.

Source

#!/bin/bash

DIR="$1"
EXT="$2"
JS_MINIFIER='slimit'
CSS_MINIFIER='cssmin'

if [ $EXT == 'js' ]
then
    MINIFIER=$JS_MINIFIER
elif [ $EXT == 'css' ]
then
    MINIFIER=$CSS_MINIFIER
fi

echo Minifier selected :: "$MINIFIER"
echo '--------'

for files in $(find "$DIR" -name "*.$EXT")
do
   minified=`$MINIFIER < $files`
   echo $minified > $files
   echo $files, minified done.
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment