GOARCH specifies the target processor architecture for compiled Go code. Setting GOARCH=wasm with GOOS=js builds a WebAssembly binary for browser execution. section 12.1.1
Build a small browser-targeted Go program with these steps:
- Create a Go module and main.go containing a Hello, WASM! program. section 12.1.1
- Run GOOS=js GOARCH=wasm go build -o main.wasm; Windows uses set commands before building. section 12.1.1
- Use go tool dist list to view supported platform combinations. section 12.1.1
- Load wasm_exec.js and main.wasm from an HTML page to run the binary in a browser. section 12.1.1
> GOOS=js GOARCH=wasm go build -o main.wasm
Shows the primary command for compiling Go code to a browser-targeted WebAssembly binary. section 12.1.1
