Skip to content

Commit 06460d8

Browse files
committed
Update README examples to use wasm32-unknown-unknown
1 parent a5dab1a commit 06460d8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![npm](https://img.shields.io/npm/v/rust-wasm-loader.svg)](https://www.npmjs.com/package/rust-wasm-loader)
44

5-
### Usage
5+
## Usage
66

77
This is a simple Webpack loader that shells out to cargo to build a Rust project targeting WebAssembly. See [this post](https://users.rust-lang.org/t/compiling-to-the-web-with-rust-and-emscripten/7627) for
88
more details on using Rust to target the web.
@@ -38,28 +38,25 @@ module.exports = {
3838

3939
Note: if you are using `file-loader`, make sure to add `.wasm` to the test field, otherwise the module will not be copied! (e.g. `test: /\.(wasm|jpg|jpeg|png|gif|svg|eot|ttf|woff|woff2)$/i,`).
4040

41-
Make sure you have the `cargo`, `rustc`, and `emsdk` binaries somewhere in your `PATH`.
41+
Make sure you have the `cargo`, `rustc`, and (optionally) `emsdk` binaries somewhere in your `PATH`.
4242
Require and initialize the wasm module:
4343

4444
```js
4545
const wasm = require('./main.rs')
46-
wasm.initialize().then(module => {
46+
wasm.then(module => {
4747
// Use your module here
48-
const doub = module.cwrap('doub', 'number', ['number'])
49-
console.log(doub(21))
48+
console.log(module.doub(21))
5049
})
5150
```
5251

5352
or with async/await:
5453

5554
```js
56-
async function loadAndUseWasm() {
57-
const wasm = require('./main.rs')
58-
const module = await wasm.initialize()
59-
const doub = module.cwrap('doub', 'number', ['number'])
60-
console.log(doub(21))
55+
async function loadwasm() {
56+
const lib = await require('./lib.rs');
57+
// Use your module here
58+
console.log(lib.doub(21));
6159
}
62-
loadAndUseWasm()
6360
```
6461

6562
### Configuration
@@ -70,6 +67,7 @@ The following options can be added to the Webpack loader query:
7067
| ---- | ----------- | -------- | ------- |
7168
| `release` | Whether or not to pass the `--release` flag to cargo | false | false |
7269
| `path` | Path to your webpack output folder relative to project root | true | '' |
70+
| `target` | Allows one to specify `wasm32-unknown-emscripten` as build target | false | 'wasm32-unknown-unknown' |
7371

7472
### Example
7573

0 commit comments

Comments
 (0)