Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is a loader for [webpack](https://webpack.js.org/) that is used for generat

The JavaScript bridge that is then generated for webpack will expose the WebAssembly functions as a Promise for interacting with.

Note: It works with `Go 1.12` for now. Stay tuned for updates :)
Note: This fork updated to with `Go 1.13`.

## webpack config

Expand Down Expand Up @@ -104,10 +104,26 @@ If you want to register a static value that's been created from Go to be availab

In JavaScript a global object is registered as `__gobridge__` which the registrations happen against.

## Example
## Examples

You'll find an example of this in action in the [`example`](https://github.com/aaronpowell/webpack-golang-wasm-async-loader/tree/master/example) folder.
Examples are provided for a CLI using NodeJS and for web using either React or Svelte. These are in the [`examples`](https://github.com/aaronpowell/webpack-golang-wasm-async-loader/tree/master/examples) directory, each with its own development and build environment.

To make an example stand-alone, copy of the corresponding example to a new directory (outside the plugin directory) and then modify the example's `webpack.config.js` so that the `.go` loader refers to this plugin. Then use `npm add --save-dev webpack-golang-wasm-async-loader` to add it to the example's dependencies.

## Environment

To build your project (and the examples) you will need the GOROOT environment variable set. So for example if using the bash shell:

node example:
```bash
GOROOT=`go env GOROOT` npm run predemo
npm run demo
```
web example (with hot reloading):
```bash
GOROOT=`go env GOROOT` npm run build
GOROOT=`go env GOROOT` npm run start
```
# Licence

MIT
Expand Down
27 changes: 27 additions & 0 deletions examples/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/node/package.json → examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"description": "",
"main": "src/index.js",
"dependencies": {
"isomorphic-fetch": "^3.0.0"
},
"devDependencies": {
},
"devDependencies": {},
"scripts": {
"predemo": "GOOS=js GOARCH=wasm go build -o ./src/main.wasm ./src/main.go",
"demo": "node ./src/index.js"
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions example/node/src/main.go → examples/node/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
"errors"
"strconv"
"syscall/js"

"../../../gobridge"
Expand All @@ -16,7 +15,7 @@ func add(this js.Value, args []js.Value) (interface{}, error) {
ret := 0

for _, item := range args {
val, _ := strconv.Atoi(item.String())
val := item.Int()
ret += val
}

Expand All @@ -34,5 +33,5 @@ func main() {
gobridge.RegisterCallback("raiseError", err)
gobridge.RegisterValue("someValue", "Hello World")

<-c
<-c // Makes the Go process wait until we want it to end
}
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "golang-wasm-async-loader-example-web",
"name": "golang-wasm-async-loader-example-web-react",
"private": true,
"version": "1.0.0",
"description": "",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Demo using Go WASM loader</title>
<title>Go WASM loader React demo</title>
</head>
<body>
<section id="main"></section>
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions example/web/src/main.go → examples/web-react/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
"errors"
"strconv"
"syscall/js"

"../../../gobridge"
Expand All @@ -16,7 +15,7 @@ func add(this js.Value, args []js.Value) (interface{}, error) {
ret := 0

for _, item := range args {
val, _ := strconv.Atoi(item.String())
val := item.Int()
ret += val
}

Expand All @@ -33,6 +32,7 @@ func main() {
gobridge.RegisterCallback("add", add)
gobridge.RegisterCallback("raiseError", err)
gobridge.RegisterValue("someValue", "Hello World")
gobridge.RegisterValue("numericValue", 123)

<-c
<-c // Makes the Go process wait until we want it to end
}
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/web-svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public/bundle*
public/*.wasm
node_modules
Loading