:q
-
First, compile Go code to WebAssembly:
GOOS=js GOARCH=wasm go build -o main.wasm main.go
-
Copy the WebAssembly JavaScript support file from local Go installation:
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" . # or cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
See https://go.dev/wiki/WebAssembly guide.
-
Final directory structure should look like:
app/ ├── index.html ├── main.wasm └── wasm_exec.js
-
Push these files to GitHub/GitLab and enable Pages.
find -name '*go' -or -name '*.html' -or -name '*.js' | entr -crs "GOOS=js GOARCH=wasm go build -o main.wasm main.go; python -m http.server"