{"id":21188434,"url":"https://github.com/drsensor/webassembly-loader","last_synced_at":"2025-07-10T02:31:29.060Z","repository":{"id":41809512,"uuid":"151703332","full_name":"DrSensor/webassembly-loader","owner":"DrSensor","description":"Yet another webpack-loader for importing wasm code :joy:","archived":false,"fork":false,"pushed_at":"2023-01-04T14:33:37.000Z","size":2198,"stargazers_count":15,"open_issues_count":23,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-10T05:50:49.584Z","etag":null,"topics":["my-study","webassembly","webpack-loader"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/DrSensor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-05T10:12:45.000Z","updated_at":"2022-01-25T16:30:32.000Z","dependencies_parsed_at":"2023-02-02T16:00:34.303Z","dependency_job_id":null,"html_url":"https://github.com/DrSensor/webassembly-loader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fwebassembly-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fwebassembly-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fwebassembly-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fwebassembly-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrSensor","download_url":"https://codeload.github.com/DrSensor/webassembly-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225613159,"owners_count":17496776,"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":["my-study","webassembly","webpack-loader"],"created_at":"2024-11-20T18:44:48.509Z","updated_at":"2024-11-20T18:44:49.340Z","avatar_url":"https://github.com/DrSensor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/WebAssembly\"\u003e\n    \u003cimg height=\"190\" alt=\"binaryen logo\" src=\"https://upload.wikimedia.org/wikipedia/commons/c/c6/Web_Assembly_Logo.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg height=\"200\" alt=\"webpack logo\" src=\"https://webpack.js.org/assets/icon-square-big.svg\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n[![npm][npm]][npm-url]\n[![size][size]][size-url]\n[![npm][npm-download]][npm-url]\n[![deps][deps]][deps-url]\n[![tests][tests]][tests-url]\n\u003c!-- [![node][node]][node-url] --\u003e\n\u003c!-- [![cover][cover]][cover-url] --\u003e\n\n# webassembly-loader\n\n\u003e this loader can also be used as a library \u003csup\u003e↙ see [who use this?](#who-use-this)\u003c/sup\u003e\n\n\u003csup\u003e\u003csup\u003etl;dr -- see [examples](#examples)\u003c/sup\u003e\u003c/sup\u003e\n\n## Motivation\n\n![future plans](https://user-images.githubusercontent.com/4953069/46924068-cbca7300-d04a-11e8-96e0-91aaa9161687.png)\n\n## Minimum Requirements\n- Node v8\n- Webpack v4\n\n## Installation\n\n```console\nnpm install webassembly-loader --save-dev\n```\nor\n```console\nyarn add webassembly-loader --dev\n```\n\n## Options\n\n### `export`\nHow wasm code would be exported. (see [examples](#examples))\n- Type: `string`\n- Default: `async`\n- Expected value:\n  - `buffer` will export wasm code as [Buffer][]\n  - `module` will export wasm code as [WebAssembly.Module][]\n  - `instance` will export wasm code as [WebAssembly.Instance][]\n  - `async` will [instantiate][webassembly.instantiate] wasm code asynchronously, return promise of both [WebAssembly.Module][] and [WebAssembly.Instance][]\n  - `async-module` will [compile][webassembly.compile] wasm code asynchronously, return promise of [WebAssembly.Module][]\n  - `async-instance` will [instantiate][webassembly.instantiate] wasm code asynchronously, return promise of [WebAssembly.Instance][]\n\n\u003cdetails\u003e\u003csummary\u003e\u003ci\u003ewebpack.config.js\u003c/i\u003e\u003c/summary\u003e\n\n```js\nmodule.exports = {\n    rules: [{\n          test: /\\.wasm$/,\n          type: \"javascript/auto\",\n          use: [{\n              loader: \"webassembly-loader\",\n              options: {\n                  export: \"async\"\n              }\n          }]\n    }]\n}\n```\n\u003c/details\u003e\n\n\u003e tips: you can use [query parameter][inline] to change export mode on demand\n\n[inline]: https://webpack.js.org/concepts/loaders/#inline\n[buffer]: https://nodejs.org/api/buffer.html\n[webassembly.module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module\n[webassembly.instance]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance\n[webassembly.instantiate]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate\n[webassembly.compile]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile\n\n## Examples\n\nSee the test cases and example projects in [*.test.ts](./test) and [examples](./examples/) for more insight.\n\n---\n\n#### `{export: 'buffer'}`\n\n```js\nimport wasmCode from \"./lib.wasm\";\n\nWebAssembly.compile(wasmCode).then(module =\u003e {\n  const instance = new WebAssembly.Instance(module);\n  console(instance.exports.add(1, 2)); // 3\n});\n```\n\n---\n\n#### `{export: 'module'}`\n\n```js\nimport wasmModule from \"./lib.wasm\";\n\nconst instance = new WebAssembly.Instance(wasmModule);\nconsole(instance.exports.add(1, 2)); // 3\n```\n\n---\n\n#### `{export: 'instance'}`\n\n```js\nimport wasm from \"./lib.wasm\";\n\nconsole(wasm.exports.add(1, 2)); // 3\n```\n\n---\n\n#### `{export: 'async'}`\n\n```js\nimport wasmInstantiate from \"./lib.wasm\";\n\nwasmInstantiate(importObject | undefined).then(({ instance, module }) =\u003e {\n  console(instance.exports.add(1, 2)); // 3\n\n  // create different instance, extra will be called in different environment\n  const differentInstance = new WebAssembly.Instance(module);\n  console(differentInstance.exports.add(1, 2)); // 6\n});\n```\n\n---\n\n#### `{export: 'async-instance'}`\n\n```js\nimport wasmInstantiate from \"./lib.wasm\";\n\nwasmInstantiate(importObject | undefined).then(instance =\u003e {\n  console(instance.exports.add(1, 2)); // 3\n});\n```\n\n---\n\n#### `{export: 'async-module'}`\n\n```js\nimport wasmInstantiate from \"./lib.wasm\";\n\nwasmCompile(importObject | undefined).then(module =\u003e {\n  const differentInstance = new WebAssembly.Instance(module);\n  console(differentInstance.exports.add(1, 2)); // 3\n});\n```\n\n---\n\n## Who use this?\n\n- [rs-jest](https://github.com/DrSensor/rs-jest)\n- [rollup-plugin-rust](https://github.com/DrSensor/rollup-plugin-rust)\n- [add yours 😉]\n\n## Contributing\n\n- [CONTRIBUTING.md](./.github/CONTRIBUTING.md) for how you can make contribution\n- [HACKING.md](./.github/HACKING.md) for technical details\n\n## Credits\n\n- [rust-native-wasm-loader](https://github.com/dflemstr/rust-native-wasm-loader)\n- [webpack-defaults](https://github.com/webpack-contrib/webpack-defaults)\n\n---\n\n## License\n[MIT](./LICENSE.md)\n\n[npm]: https://img.shields.io/npm/v/webassembly-loader.svg\n[npm-url]: https://npmjs.com/package/webassembly-loader\n[npm-download]: https://img.shields.io/npm/dm/webassembly-loader.svg\n[node]: https://img.shields.io/node/v/webassembly-loader.svg\n[node-url]: https://nodejs.org\n[deps]: https://david-dm.org/DrSensor/webassembly-loader.svg\n[deps-url]: https://david-dm.org/DrSensor/webassembly-loader\n[tests]: https://img.shields.io/circleci/project/github/DrSensor/webassembly-loader.svg\n[tests-url]: https://circleci.com/gh/DrSensor/webassembly-loader\n[cover]: https://codecov.io/gh/DrSensor/webassembly-loader/branch/master/graph/badge.svg\n[cover-url]: https://codecov.io/gh/DrSensor/webassembly-loader\n[size]: https://packagephobia.now.sh/badge?p=webassembly-loader\n[size-url]: https://packagephobia.now.sh/result?p=webassembly-loader\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrsensor%2Fwebassembly-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrsensor%2Fwebassembly-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrsensor%2Fwebassembly-loader/lists"}