Skip to content

Instantly share code, notes, and snippets.

@607011
Created January 7, 2019 05:25
Show Gist options
  • Select an option

  • Save 607011/47f6f21b0f06f0456eb2e88a8ec11008 to your computer and use it in GitHub Desktop.

Select an option

Save 607011/47f6f21b0f06f0456eb2e88a8ec11008 to your computer and use it in GitHub Desktop.
Minify HTML/CSS and JavaScript files, then deploy them via SSH
#!/bin/bash
DIST=dist/
DEST=host://path/to/html
JSFILES="worker.js wichtel.js"
HTMLFILES="index.html"
OTHERFILES=""
echo Cleaning up ...
rm -rf $DIST
mkdir $DIST
echo Compressing JavaScript ...
for f in $JSFILES; do
uglifyjs --compress --mangle -o $DIST/$f -- $f
done
echo Compressing HTML ...
for f in $HTMLFILES; do
html-minifier \
--collapse-whitespace \
--remove-comments \
--remove-optional-tags \
--remove-script-type-attributes \
--remove-tag-whitespace \
--use-short-doctype \
--minify-css true \
--minify-js true \
$f -o $DIST/$f
done
echo Copying other files ...
for f in $OTHERFILES; do
cp -a $f $DIST
done
echo Deploying to $DEST ...
FILES="$HTMLFILE $JSFILES $OTHERFILES"
cd $DIST
rsync -rqtazv $FILES $DEST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment