Configure your environment

Before startint your first project, it's best to spend some time setting up your work environment. This will allow you to save working time and productivity.

I personally prefer to work with visual studio code, but the explanations above will be easily transposable to your case.

Use WebAssembly in your IDE

By default, the GOOS AND GOARCH follow your config hardware. The binary product by go must be in "webassembly" format. To configure Go, you must set the GOOS and GOARCH env variable with value:

GOOS=js and GOARCH=wasm

For visual studio code, create a .vscode/settings.json file with:

{
    "go.buildTags": "js,wasm",
    "go.testEnvVars": {
        "GOARCH":"wasm",
        "GOOS": "js",
    },
    "go.testTags": "js,wasm",

}

Live testing

The normal way to test your app is compile your app in a wasm file with go or tinygo, upload it to a static serve file, and test with your favorite browser.

This task can be automated , but consume lots of time. Thanks to https://github.com/agnivade/wasmbrowsertest you can live testings your apps with the "go run" standard function.

The only drawback is that solution works only with chrome for the moment.

My fork of wasmbrowsertest contains a useful function for hogusuru, this function will be integrated in some further iteration of wasmbrowsertest

Install wasmbrowsertest:

go install github.com/realPy/wasmbrowsertest@f20c27876ce20bbce5b971af53a67a745825a7d3
sudo cp ~/go/bin/wasmbrowsertest /usr/local/bin/go_js_wasm_exec

You are now ready to run your first project now

Last updated