Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using this script you can minify the CSS and JS files.
#!/bin/bash
#require: uglifyjs and uglifycss npm package
# https://www.npmjs.com/package/uglify-js
# https://www.npmjs.com/package/uglifycss
#Start JS minification
read -p 'Enter the unminified JS directory absolute path: ' JS_DIR
echo "Creating the minified directory...";
mkdir -p $JS_DIR/minified;
for f in `find $JS_DIR/ -type f -name "*.js" ! -name "*.min.*"`;
do
FILE_BASENAME=`basename $f .js`
echo "Minifying the {$f} file.";
uglifyjs $f -o $JS_DIR/minified/$FILE_BASENAME.min.js
done;
#Start CSS minification
echo "Do you want to minify the CSS files? [Y,n]"
read input
if [[ $input == "Y" || $input == "y" ]]; then
read -p 'Enter the unminified CSS directory absolute path: ' CSS_DIR
echo "Creating the minified directory...";
mkdir -p $CSS_DIR/minified;
for f in `find $CSS_DIR/ -type f -name "*.css" ! -name "*.min.*"`;
do
FILE_BASENAME=`basename $f .css`
echo "Minifying the {$f} file.";
uglifycss $f --output $CSS_DIR/minified/$FILE_BASENAME.min.css
done;
else
echo "EXIT!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.