WebAssembly (Wasm)
WebAssembly (Wasm) is a binary code that you can run in a browser. GoLand supports generation of WASM files from GO files. You can read more about You can read more about WebAssembly in documentation at webassembly.org.
Open settings , and navigate to Go | Build Tags.
From the OS list, select js.
From the Arch list, select wasm.
Click OK.
Click Run | Edit Configurations on the main toolbar.
Click Add New Configuration icon (
) or press .
From the Run kind list, select File.
In the Files field, add the name of the GO file that you want to execute (for example,
main.go
).Clear the Run after build checkbox.
In the Environment field, click the Browse button at the end of the field.
In the Environment Variables dialog, add two environment variables:
GOOS=js
GOARCH=wasm
In the Go tool arguments field, replace the
-i
argument with-o main.wasm
, wheremain.wasm
is the name of the future WASM file.Click OK.
Click the Run <configuration_name > icon or press . As the result, in the Project tool window a new WASM file is created.
Gif
tip
To add an environment variable, click the Add icon. In the Name column, specify the variable name. In the Value column, specify the variable value.