Skip to content

Commit 4e19ead

Browse files
authored
Fix the wasm2js example (#1750)
This needed and update now that we're explicitly importing `*.wasm` to import `*.js` instead. Additionally this was moved over to the `web` target to avoid needing Webpack Closes #1743
1 parent 1f39a30 commit 4e19ead

File tree

7 files changed

+11
-47
lines changed

7 files changed

+11
-47
lines changed

examples/wasm2js/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ $ ./build.sh
1414

1515
(or running the commands on Windows manually)
1616

17-
and then visiting http://localhost:8080 in a browser should run the example!
17+
and then visiting http://localhost:8000 in a browser should run the example!

examples/wasm2js/build.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
set -ex
44

55
# Compile our wasm module and run `wasm-bindgen`
6-
wasm-pack build
6+
wasm-pack build --target web
77

88
# Run the `wasm2js` tool from `binaryen`
99
wasm2js pkg/wasm2js_bg.wasm -o pkg/wasm2js_bg.js
1010

11-
# Move our original wasm out of the way to avoid cofusing Webpack.
12-
mv pkg/wasm2js_bg.wasm pkg/wasm2js_bg.bak.wasm
11+
# Update our JS shim to require the JS file instead
12+
sed -i 's/wasm2js_bg.wasm/wasm2js_bg.js/' pkg/wasm2js.js
1313

14-
npm install
15-
npm run serve
14+
http

examples/wasm2js/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
<body>
66
<p>Open up the developer console to see "Hello, World!"</p>
77
</body>
8+
<script src=index.js type=module></script>
89
</html>

examples/wasm2js/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Note that since we're not using `WebAssembly` we can do a synchronous import
2-
// here!
3-
import { run } from './pkg/wasm2js';
4-
run();
1+
// Import our JS shim and initialize it, executing the start function when it's
2+
// ready.
3+
import init from './pkg/wasm2js.js';
4+
init();

examples/wasm2js/package.json

-13
This file was deleted.

examples/wasm2js/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern "C" {
77
fn log(s: &str);
88
}
99

10-
#[wasm_bindgen]
10+
#[wasm_bindgen(start)]
1111
pub fn run() {
1212
log("Hello, World!");
1313
}

examples/wasm2js/webpack.config.js

-23
This file was deleted.

0 commit comments

Comments
 (0)