Skip to content

Commit

Permalink
update readme for bundler instructions, upgrade to 0.2.76 bindgen, dr…
Browse files Browse the repository at this point in the history
…op filename for rs files (needed for cjs)

Signed-off-by: ks2211 <[email protected]>
  • Loading branch information
ks2211 committed Aug 24, 2021
1 parent aaaf614 commit c55c160
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,38 @@ $ npm install @wasmcloud/wasmcloud-js
</script>
```

**With a bundler**

There are some caveats to using with a bundler:

* The module contains `.wasm` files that need to be present alongside the final build output. Using `webpack-copy-plugin` can solve this issue.

* Using the es6 imports is currently broken due to `webpack` bundling and the `.wasm` file -- this is being tracked/fixed.

```javascript
import { wasmcloudjs } from '@wasmcloud/wasmcloud-js/dist/cjs/wasmcloud'

(async() => {
const host = await wasmcloudjs.startHost('default', false, ['ws://localhost:4222'])
console.log(host);
})()

```

```javascript
// webpack config, add this to the plugin section
plugins: [
new CopyPlugin({
patterns: [
{
from: 'node_modules/@wasmcloud/wasmcloud-js/dist/cjs/*.wasm',
to: '[name].wasm'
}
]
}),
]
```

**Node**

*IN PROGRESS* - NodeJS does not support WebSockets natively (required by nats.ws)
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "@wasmcloud/wasmcloud-js",
"version": "1.0.2",
"version": "1.0.3",
"description": "wasmcloud host in JavaScript/Browser",
"main": "dist/wasmcloud.js",
"browser": "dist/wasmcloud.js",
"module": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
"dist",
"src",
"README.md"
"README.md",
"wasmcloud-rs-js"
],
"scripts": {
"build": "npm run clean && npm run build:browser && npm run build:cjs",
Expand Down Expand Up @@ -60,7 +62,6 @@
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"copy-webpack-plugin": "^9.0.1",
"esbuild": "^0.12.20",
"eslint": "^7.32.0",
"mocha": "^9.0.3",
"path": "^0.12.7",
Expand Down
2 changes: 1 addition & 1 deletion wasmcloud-rs-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.63"
wasm-bindgen = "0.2.76"
wascap = "0.6.0"
getrandom = { version = "0.2", features = ["js"] }
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
Expand Down
3 changes: 1 addition & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const baseConfig = {
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, 'wasmcloud-rs-js'),
extraArgs: '--target bundler',
outDir: path.resolve(__dirname, 'wasmcloud-rs-js', 'pkg'),
outName: 'wasmcloud_rs_js'
outDir: path.resolve(__dirname, 'wasmcloud-rs-js', 'pkg')
})
],
experiments: {
Expand Down

0 comments on commit c55c160

Please sign in to comment.