diff --git a/.gitignore b/.gitignore index ec293f5..4181c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ public/css/tailwind.css # js node_modules public/js/*.min.js + +# hot reload +public/__hotreload__ diff --git a/Makefile b/Makefile index 8d770cc..9546aa7 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,7 @@ hermes: $(SOURCE) run: tailwindcss -i public/css/base.css -o public/css/tailwind.css templ generate -path pages - go run . \ No newline at end of file + go run . + +dev: + bash hotreload.sh diff --git a/hotreload.sh b/hotreload.sh new file mode 100644 index 0000000..db89418 --- /dev/null +++ b/hotreload.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +BINARY=hermes +PID= + +set -e + +function restart() { + date +%s.%N > public/__hotreload__ + set +e + [[ -z "$PID" ]] || kill -15 $PID + make build -B + set -e + ./$BINARY 2>&1 & + PID=$(pidof $BINARY) +} + +function cleanup() { + rm -f public/__hotreload__ + [[ -z "$PID" ]] || kill -15 $PID +} +trap cleanup EXIT + +restart +while inotifywait -r -e modify fonts/ lib/ pages/ public/ server/; do + restart +done diff --git a/pages/components/head.templ b/pages/components/head.templ index 975e6ec..20c0c8e 100644 --- a/pages/components/head.templ +++ b/pages/components/head.templ @@ -23,6 +23,9 @@ templ Head() { }' /> + if ctx.Value("env") != "production" { + + }