DrSensor / DrSensor/webassembly-loader

Add option for instanceless which directly export wasm function

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
good first issue hacktoberfest help wanted
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.