wasmgo

Compiles Go to WASM and deploys to the jsgo.io CDN

  • 所有者: dave/wasmgo
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

wasmgo

The wasmgo command compiles Go to WASM, and serves the binary locally or deploys to the jsgo.io CDN.

Install

go get -u github.com/dave/wasmgo

Serve command

wasmgo serve [flags] [package]

Serves the WASM with a local web server (default to port 8080). Refresh the browser to recompile.

Deploy command

wasmgo deploy [flags] [package]

Deploys the WASM to the jsgo.io CDN.

Global flags

-b, --build string     Build tags to pass to the go build command.
-c, --command string   Name of the go command. (default "go")
-f, --flags string     Flags to pass to the go build command.
-h, --help             help for wasmgo
-i, --index string     Specify the index page template. Variables: Script, Loader, Binary. (default "index.wasmgo.html")
-o, --open             Open the page in a browser. (default true)
-v, --verbose          Show detailed status messages.

Deploy flags

-j, --json              Return all template variables as a json blob from the deploy command.
-t, --template string   Template defining the output returned by the deploy command. Variables: Page, Script, Loader, Binary. (default "{{ .Page }}")

Serve flags

-p, --port int   Server port. (default 8080)

Package

Omit the package argument to use the code in the current directory.

Examples

Here's a simple hello world:

wasmgo serve github.com/dave/wasmgo/helloworld

The page (http://localhost:8080/) opens in a browser.

Here's an amazing 2048 clone from hajimehoshi:

go get -u github.com/hajimehoshi/ebiten/examples/2048/...
wasmgo deploy -b=example github.com/hajimehoshi/ebiten/examples/2048

The deployed page opens in a browser.

Index

You may specify a custom index page by including index.wasmgo.html in your project or by using the index
command line flag.

Your index page should look something like this:

<html>
<head><meta charset="utf-8"></head>
<body>
	<script src="{{ .Script }}"></script>
	<script src="{{ .Loader }}"></script>
</body>
</html>

Template variables

The index page template and the -t flag are both Go templates with several variables available:

  • Page
    The URL of the page on jsgo.io (deploy command output only).

  • Script
    To load and execute a WASM binary, a some JS bootstap code is required. The wasmgo command uses a minified
    version of the example in the official Go repo.
    The URL of this script is the Script template variable.

  • Loader
    The loader JS is a simple script that loads and executes the WASM binary. It's based on the example
    in the official Go repo
    ,
    but simplified to execute the program immediately instead. The URL of this script is the Loader template variable.

  • Binary
    The URL of the WASM binary file.

Static files

Unfortunately wasmgo does not host your static files. I recommend using rawgit.com
to serve static files.

Package splitting

The wasmgo deploy can't yet split the binary output by Go package, can you help?

主要指標

概覽
名稱與所有者dave/wasmgo
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2018-08-14 18:31:36
推送於2023-03-07 00:43:48
最后一次提交2019-12-16 09:45:42
發布數2
最新版本名稱v0.0.2 (發布於 )
第一版名稱v0.0.1 (發布於 )
用户参与
星數145
關注者數11
派生數13
提交數24
已啟用問題?
問題數6
打開的問題數3
拉請求數1
打開的拉請求數1
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?