-
-
Notifications
You must be signed in to change notification settings - Fork 387
Build and deploy
Having a working progressive web app built with the go-app package requires 2 parts to be built.
The server is a classic Go program. It uses the Handler to serve the WebAssembly part. It is built with the standard go build command:
go build
See the HTTP Handler topic.
The WebAssembly part is where all the UI is implemented. It is served by the server part from the /app.wasm
path. Building this requires using the go build command while specifying the wasm
architecture and the js
operating system:
GOARCH=wasm GOOS=js go build -o app.wasm
Once built it must be moved in the same directory as the server.
demo-server # Server directory
├── app.wasm # Wasm app binary
└── demo-server # Server binary
While unit testing the server is a standard go test command, testing the WebAssembly part requires some setup.
Since it is working in a web browser, the unit tests should also occur in a browser environment. You can setup go test with wasm to run on a browser by the following command:
go get -u github.com/agnivade/wasmbrowsertest && \
mv $GOPATH/bin/wasmbrowsertest $GOPATH/bin/go_js_wasm_exec
wasmbrowsertest
is a program that allows go test to be executed in Chrome in headless mode.
Then, as for the build command, the unit test can be launched by specifying the wasm
architecture and the js
operating system:
GOARCH=wasm GOOS=js go test