Created
January 7, 2019 05:25
-
-
Save 607011/47f6f21b0f06f0456eb2e88a8ec11008 to your computer and use it in GitHub Desktop.
Minify HTML/CSS and JavaScript files, then deploy them via SSH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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