wasm-bindgen/examples/without-a-bundler/index.html

45 lines
1.6 KiB
HTML
Raw Normal View History

<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<!--
This is the JS generated by the `wasm-pack` build command
The script here will define a `wasm_bindgen` global where all
functionality can be accessed such as instantiation and the actual
functions (examples below).
You can customize the name of the file here with the `out-name` CLI flag
to `wasm-bindgen`. You can also customize the name of the global exported
here with the `no-modules-global` flag.
-->
<script src='./pkg/without_a_bundler.js'></script>
<script>
// Import functionality from the wasm module, but note that it's not quite
// ready to be used just yet.
const { add } = wasm_bindgen;
async function run() {
// First up we need to actually load the wasm file, so we use the
// exported global to inform it where the wasm file is located on the
// server, and then we wait on the returned promies to wait for the
// wasm to be loaded.
//
// Note that instead of a string here you can also pass in an instance
// of `WebAssembly.Module` which allows you to compile your own module.
await wasm_bindgen('./pkg/without_a_bundler_bg.wasm');
// And afterwards we can use all the functionality defined in wasm.
const result = add(1, 2);
console.log(`1 + 2 = ${result}`);
if (result !== 3)
throw new Error("wasm addition doesn't work!");
}
run();
</script>
</body>
</html>