Skip to content

Instantly share code, notes, and snippets.

@pitabas106
Created September 20, 2019 03:29
Show Gist options
  • Save pitabas106/f1e15d2dfab2127a534cd15cc65ad830 to your computer and use it in GitHub Desktop.
Save pitabas106/f1e15d2dfab2127a534cd15cc65ad830 to your computer and use it in GitHub Desktop.
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