{"id":19471581,"url":"https://github.com/aaronpowell/webpack-golang-wasm-async-loader","last_synced_at":"2025-08-25T18:48:05.853Z","repository":{"id":43596617,"uuid":"167268315","full_name":"aaronpowell/webpack-golang-wasm-async-loader","owner":"aaronpowell","description":"A webpack loader for generating Golang WebAssembly bundles using an async interaction model for calling the Golang code from JavaScript","archived":false,"fork":false,"pushed_at":"2023-01-14T00:32:35.000Z","size":695,"stargazers_count":72,"open_issues_count":28,"forks_count":29,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-17T19:45:33.199Z","etag":null,"topics":["go","golang","wasm","webassembly","webpack"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aaronpowell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-23T23:10:14.000Z","updated_at":"2024-09-09T04:31:20.000Z","dependencies_parsed_at":"2023-02-09T18:00:33.698Z","dependency_job_id":null,"html_url":"https://github.com/aaronpowell/webpack-golang-wasm-async-loader","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2Fwebpack-golang-wasm-async-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2Fwebpack-golang-wasm-async-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2Fwebpack-golang-wasm-async-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2Fwebpack-golang-wasm-async-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronpowell","download_url":"https://codeload.github.com/aaronpowell/webpack-golang-wasm-async-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227777694,"owners_count":17818455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","wasm","webassembly","webpack"],"created_at":"2024-11-10T19:02:24.067Z","updated_at":"2024-12-03T13:46:01.995Z","avatar_url":"https://github.com/aaronpowell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status][build]][build-url]\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg width=\"200\" height=\"200\"\n      src=\"https://webpack.js.org/assets/icon-square-big.svg\"\u003e\n  \u003c/a\u003e\n  \u003ch1\u003eGolang WebAssembly Async Loader\u003c/h1\u003e\n  \u003cp\u003eGenerates a WASM package from Golang and provides an async interface for working with it\u003c/p\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003eInstall\u003c/h2\u003e\n\n```bash\nnpm install --save-dev golang-wasm-async-loader\n```\n\nThis is a loader for [webpack](https://webpack.js.org/) that is used for generating [WebAssembly](https://webassembly.org/) (aka WASM) bundles from [Go](https://golang.org).\n\nThe JavaScript bridge that is then generated for webpack will expose the WebAssembly functions as a Promise for interacting with.\n\nNote: It works with `Go 1.12` for now. Stay tuned for updates :)\n\n## webpack config\n\n```js\nmodule.exports = {\n    ...\n    module: {\n        rules: [\n            {\n                test: /\\.go/,\n                use: ['golang-wasm-async-loader']\n            }\n        ]\n    },\n    node: {\n        fs: 'empty'\n    }\n};\n```\n\n# Using in your code\n\nYou import your Go code just like any other JavaScript module you might be working with. The webpack loader will export a default export that has the functions you registered in Go on it. Unfortunately it currently doesn't provide autocomplete of those function names as they are runtime defined.\n\n```js\nimport wasm from './main.go'\n\nasync function init() {\n  const result = await wasm.add(1, 2);\n  console.log(result);\n\n  const someValue = await wasm.someValue();\n  console.log(someValue);\n}\n```\n\nHere's the `main.go` file:\n\n```go\npackage main\n\nimport (\n\t\"strconv\"\n\t\"syscall/js\"\n\t\"github.com/aaronpowell/webpack-golang-wasm-async-loader/gobridge\"\n)\n\nfunc add(i []js.Value) (interface{},error) {\n\tret := 0\n\n\tfor _, item := range i {\n\t\tval, _ := strconv.Atoi(item.String())\n\t\tret += val\n\t}\n\n\treturn ret, nil\n}\n\nfunc main() {\n\tc := make(chan struct{}, 0)\n\n\tgobridge.RegisterCallback(\"add\", add)\n\tgobridge.RegisterValue(\"someValue\", \"Hello World\")\n\n\t\u003c-c\n}\n```\n\n## How does it work?\n\nAs part of this repository a Go package has been created to improve the interop between the Go WASM runtime and work with the async pattern the loader defines.\n\nTo do this a function is exported from the package called `RegisterCallback` which takes two arguments:\n\n* A `string` representing the name to register it as in JavaScript (and what you'll call it using)\n* The `func` to register as a callback\n  * The `func` must has a signature of `(args js.Value) (interface{}, error)` so you can raise an error if you need\n\nIf you want to register a static value that's been created from Go to be available in JavaScript you can do that with `RegisterValue`, which takes a name and a value. Values are converted to functions that return a Promise so they can be treated asynchronously like function invocations.\n\nIn JavaScript a global object is registered as `__gobridge__` which the registrations happen against.\n\n## Example\n\nYou'll find an example of this in action in the [`example`](https://github.com/aaronpowell/webpack-golang-wasm-async-loader/tree/master/example) folder.\n\n# Licence\n\nMIT\n\n# Credit\n\nAaron Powell\n\n[build]: https://aaronpowell.visualstudio.com/webpack-golang-wasm-async-loader/_apis/build/status/aaronpowell.webpack-golang-wasm-async-loader?branchName=master\u0026label=Built%20on%20Azure%20🐱%E2%80%8D💻\n[build-url]: https://aaronpowell.visualstudio.com/webpack-golang-wasm-async-loader/_build/latest?definitionId=16?branchName=master\n\n[npm]: https://img.shields.io/npm/v/golang-wasm-async-loader.svg\n[npm-url]: https://npmjs.com/package/golang-wasm-async-loader\n\n[node]: https://img.shields.io/node/v/golang-wasm-async-loader.svg\n[node-url]: https://nodejs.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronpowell%2Fwebpack-golang-wasm-async-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronpowell%2Fwebpack-golang-wasm-async-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronpowell%2Fwebpack-golang-wasm-async-loader/lists"}