DrSensor / DrSensor/webassembly-loader
Add option for instanceless which directly export wasm function
- Dominant language
- TypeScript
- Stars
- 16
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
> from https://github.com/DrSensor/rollup-plugin-rust/issues/11
Webpack 4 has a feature to import exported function in wasm file directly (see [here](https://github.com/webpack/webpack/tree/master/examples/wasm-simple#mathjs)). Probably people more comfortable if this behavior is set as default. I call it `instanceless` mode :yum:
What need to do:
- [ ] make wrapper by taking inspiration from [.asWebAssembly.Instance][] and name it `Instanceless`. The trick is by directly export [instance.exports][]. For example
```js
asWebAssembly: {
Instanceless: `${exportString} (new WebAssembly.Instance(...))).exports`
}
```
- [ ] use that in file `transform.ts` by making new case `instanceless` in the [switch statement][]
- [ ] make default [export option] `instanceless`
- [ ] add the example usage in [README.md#examples][]. For example:
#### `{export: 'instanceless'}`
```js
import { add } from './lib.wasm'
console(add(1, 2)); // 3
```
- [ ] create the test case in [export.spec.js][]
---------
### Good Luck :+1:
If anyone have a better idea or need something please let me know :wink:
> Ah yes, don't forget to read [the Contribution and Technical Guideline] and [make the PR can be edited by the maintainer][] :hatching_chick:
[make the PR can be edited by the maintainer]: https://help.github.com/assets/images/help/pull_requests/allow-maintainers-to-make-edits-sidebar-checkbox.png
[the Contribution and Technical Guideline]: https://github.com/DrSensor/webassembly-loader#contributing
[README.md#examples]: https://github.com/DrSensor/webassembly-loader/blob/master/README.md#examples
[export.spec.js]: https://github.com/DrSensor/rollup-plugin-rust/blob/master/test/export.spec.js
[export option]: https://github.com/DrSensor/webassembly-loader/blob/3c6af566ea83c3a36f15b4aee3ff4fb652323546/src/index.ts#L9
[switch statement]: https://github.com/DrSensor/webassembly-loader/blob/3c6af566ea83c3a36f15b4aee3ff4fb652323546/src/transform.ts#L38-L53
[instance.exports]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance#Instance_properties
[.asWebAssembly.Instance]: https://github.com/DrSensor/webassembly-loader/blob/3c6af566ea83c3a36f15b4aee3ff4fb652323546/src/wrapper.ts#L18-L22
Contributor guide
Research direction
Start by reading src/wrapper.ts and the switch in src/transform.ts, then inspect the default export option in src/index.ts. Run test/export.spec.js and review the README examples. Done means the instanceless export mode is implemented, selected by default, documented with the shown usage, and covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, wasm
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100