Last active
October 25, 2025 14:58
-
-
Save SamuelDavis/171fc3c1fd2ea000477f9ca0768d728c to your computer and use it in GitHub Desktop.
Deploy to gh-pages for projects with `npm run build` to `dist/` (e.g. Vite)
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
| function deploy() { | |
| HOST=${1:-'[email protected]:SamuelDavis'} | |
| DOMAIN=${2:-'sdavis.online'} | |
| REMOTE_ORIGIN=$(git config --get remote.origin.url) | |
| if [ $? -ne 0 ]; then | |
| echo "Git repository not found." >&2 | |
| return | |
| fi | |
| REPO_NAME=$(basename -s .git $REMOTE_ORIGIN) | |
| npm run build | |
| if [ $? -ne 0 ]; then | |
| return | |
| fi | |
| cd dist | |
| echo "$REPO_NAME.$DOMAIN" > CNAME | |
| git init | |
| git add -A | |
| git commit -m 'deploy' | |
| BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| git push -f "$HOST/$REPO_NAME.git" "$BRANCH:gh-pages" | |
| cd - | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment