Destroyed WebAssembly (markdown)

Hajime Hoshi 2019-11-03 19:05:27 +09:00
parent 4b5196dc85
commit bf9660c0a7

@ -1,60 +0,0 @@
The easiest way is to Dave's awesome [wasmgo](https://github.com/dave/wasmgo)
This article introduces a regular way to build an Ebiten app as a WebAssembly port.
# Requirements
* Go 1.11 or later
* Ebiten 1.8.0 or later
# Option 1. WasmGo
Upload your package via wasmgo. See https://github.com/dave/wasmgo
# Option 2. WasmServe
```sh
go get github.com/hajimehoshi/wasmserve
cd yourgame
wasmserve
```
Then access `http://localhost:8080/`.
# Option 3. Regular
## Compile your game
```sh
GOOS=js GOARCH=wasm go build -o yourgame.wasm github.com/yourname/yourgame
```
## Copy `wasm_exec.js` to execute the Wasm binary
```sh
cp $GOROOT/misc/wasm/wasm_exec.js .
```
Source: [https://github.com/golang/go/tree/master/misc/wasm](https://github.com/golang/go/tree/master/misc/wasm)
## Create an HTML
```html
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
// Polyfill
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
WebAssembly.instantiateStreaming(fetch("yourgame.wasm"), go.importObject).then(result => {
go.run(result.instance);
});
</script>
```
Then open the HTML (you might need local HTTP server).