Skip to content

Build and deploy

Maxence Charriere edited this page Mar 5, 2020 · 18 revisions

Table of Contents

Build

Having a working progressive web app built with the go-app package requires 2 parts to be built.

build

Server

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.

WebAssembly app

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, app.wasm must be moved in the same directory as the server.

demo-server        # Server directory
├── app.wasm       # Wasm app binary
└── demo-server    # Server binary

Unit tests

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

Deploy

From local machines to cloud providers, progressive web apps built with go-app can be deployed in multiple places. Refer to the demo examples to see how it can be done:

Sources Description
hello-local Hello app that runs on a local server.
hello-docker Hello app that run in a Docker container.
hello-appengine Hello app that run on Google Cloud App Engine.
Clone this wiki locally