0.1.9 • Published 3 years ago

wasm-go v0.1.9

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

wasm-go

Youtube Video

西瓜视频

Easy start use go wasm write frontend project

  • Need install golang
  • Need install nodejs

feature

  • Auto build on change
  • Auto reload brower on change
  • Auto create frontend wasm
  • Watch project
  • Proxy

Start

1 - Creaet go mod project

mkdir my-project
cd my-project
go mod init my-project
touch main.go

2 - Edit main.go

package main

import (
	"syscall/js"
)

func main() {
	document := js.Global().Get("document")

	h2 := document.Call("createElement", "h2")
	h2.Set("textContent", "Hello wasm-go")

	document.Get("body").Call("appendChild", h2)

	// keep go runtime
	c := make(chan struct{})
	<-c
}

Install wasm-go

npm i -g wasm-go

Dev start

At my-project root dir:

wasm-go

Build release

wasm-go --release

Change config

Change wasm-go.config.js

const { resolve } = require("path");

module.exports = {
  gzip: false,
  host: "127.0.0.1",
  port: 3200,
  goEntry: resolve(__dirname, "main.go"),
  srcPath: resolve(__dirname, "src"),
  publicPath: resolve(__dirname, "public"),
  publicPrefix: "/",
  proxy: [
    {
      prefix: "/ping",
      upstream: "http://127.0.0.1:5050",
      rewritePrefix: "/ping",
      http2: false,
    },
  ],
  build: (release, publicPath, goEntry) => {
    return `GOOS=js GOARCH=wasm go build ${release} -o ${publicPath}/main.wasm ${goEntry}`;
  },
};
0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago