saq
A toolchain-agnostic live reload tool that supports automatic reloading of the
browser when a file is changed.
Install
go install libdb.so/saq@latest
Basic Example
Watch and rebuild a Go server
This example tells saq to run the given command when a file change is
detected. The browser is automatically reloaded when the server is up.
saq \
-s http://localhost:8081 \
-t localhost:8080 \
-i ./... \
-x .git \
--gitignoreFile .gitignore \
-- bash -c 'go build && ./server --http localhost:8081'
# or equivalently
saq -- bash -c 'go build && ./server --http localhost:8081'
[!NOTE]
go run does not propagate signals to the child process, so you should not
use go run with saq. See https://github.com/golang/go/issues/40467.
Serve the current directory
This example serves the current directory and reloads the browser when a file
is changed.
saq \
-s http://localhost:8081 \
-F http://localhost:8081 \
-t localhost:8080
# or equivalently
saq -F http://localhost:8081
In this example, we signal saq to start a file server at port :8081 and proxy
that server to the browser at port :8080. Everything else works the same as the
previous example.
How it works
saq acts as a reverse proxy. It works as follows:
- It injects a script into the HTML response that
fetches an endpoint that
blocks until a file change is detected.
- When a file change is detected, the server process is restarted, which
saq
then tries to connect by sending a HEAD request to the server.
- Once the server is up, the browser is reloaded.
saq only works on Linux due to its dependency on illarion/gonotify.
Help
Usage: saq [flags...] argv...
Flags:
--browser-open-once only open browser once, otherwise it will open if there are no active browsers (default true)
-x, --exclude strings exclude directories/paths/globs (prefix ./ is required for path) (default [*.tmpl,./vendor])
-F, --file-server string file server address to listen on, empty to disable
--generated-check string command to check if a file is generated, executes $SHELL or /bin/sh otherwise (default "[[ $FILE == *.go ]] && grep \"^// Code generated by\" \"$FILE\"")
--gitignore string gitignore file to use, empty to disable (default ".gitignore")
-i, --include string include directory (default ".")
--no-browser do not open browser
-s, --source string source URL of the upstream server (default "http://localhost:8081")
-t, --target string target address to listen on (default "localhost:8080")
-v, --verbose verbose logging
Who made the name?
@FreezingSnail