Skip to content

Commit d1054c8

Browse files
committed
Add basic docs
1 parent 212ab58 commit d1054c8

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

README.md

+60-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,69 @@
11
# vue-wasm
22

3-
> Vue web assembly loader
3+
> A Vue plugin to help expose your Web Assembly functions in your Vue application
44
5-
## Build Setup
5+
![example](src/assets/Vue-wasm.png)
66

7-
``` bash
8-
# install dependencies
9-
npm install
7+
## Install
8+
You can use NPM or Yarn to add this plugin to your project
9+
```bash
10+
npm install vue-wasm
11+
# or
12+
yarn add vue-wasm
13+
```
14+
15+
### Webpack Loader
16+
This package includes a loader to allow you to easily import your `.wasm` files into your webpack project. Just add the following to your webpack config...
17+
18+
```js
19+
// build/webpack.base.conf.js
20+
module: {
21+
rules: [
22+
...
23+
{
24+
test: /\.wasm$/,
25+
loaders: ['wasm-loader']
26+
}
27+
]
28+
}
29+
```
30+
### Basic
31+
Simply import the `vue-wasm` plugin and your Web Assembly modules and then install the plugin whilst passing through an object of `wasm` modules. *The key of the each module will be used to namespace the modules*
32+
33+
```js
34+
import VueWasm from 'vue-wasm';
35+
import addModule from './assets/wasm/add.wasm';
1036

11-
# serve with hot reload at localhost:8080
12-
npm run dev
37+
VueWasm(Vue, { modules: { add: addModule } });
38+
```
39+
### Await load
40+
If you need to use your Web Assembly functions in the mounted or created lifecycle hooks, you will need to use a little hack to wait for the plugin to load before initialising your Vue app.
41+
42+
```js
43+
//main.js
44+
import VueWasm from 'vue-wasm';
45+
import add from './assets/wasm/add.wasm';
46+
47+
const init = async () => {
48+
await VueWasm(Vue, { modules: { add } });
49+
/* eslint-disable no-new */
50+
new Vue({
51+
el: '#app',
52+
template: '<App/>',
53+
components: { App },
54+
});
55+
};
56+
57+
init();
58+
```
1359

14-
# build for production with minification
15-
npm run build
60+
## Usage
61+
This will add a `$wasm` object to all of your Vue components. *Note that your functions are nested under the module key that you used whilst installing the plugin.*
1662

17-
# build for production and view the bundle analyzer report
18-
npm run build --report
63+
```js
64+
// App.vue
65+
mounted() {
66+
console.log(this.$wasm.add.addOne(2)) // 3
67+
},
1968
```
2069

21-
For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).

src/assets/Vue-wasm.png

30.4 KB
Loading

0 commit comments

Comments
 (0)