-
-
Notifications
You must be signed in to change notification settings - Fork 671
WebAssembly
Hajime Hoshi edited this page Oct 10, 2018
·
28 revisions
The easiest way is to Dave's awesome wasmgo
This article introduces a regular way to build an Ebiten app as a WebAssembly port.
- Go 1.11
- Ebiten master branch (1.8.0-alpha.0.XXX) / 2.0.0-alpha
Upload your package via wasmgo. See https://github.com/dave/wasmgo
go get github.com/hajimehoshi/wasmserve
cd yourgame
wasmserve
Then access http://localhost:8080/
.
GOOS=js GOARCH=wasm go build -o yourgame.wasm github.com/yourname/yourgame
cp $GOROOT/misc/wasm/wasm_exec.js .
Source: https://github.com/golang/go/tree/master/misc/wasm
<!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>
TBD