Integrate parcel
This commit is contained in:
parent
6f36bb344a
commit
5e839f862c
6 changed files with 3462 additions and 5 deletions
2
Makefile
Normal file
2
Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
build:
|
||||
wasm-pack build --target=web
|
12
src/lib.rs
12
src/lib.rs
|
@ -7,8 +7,12 @@ pub mod player_interaction;
|
|||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_option(some: bool) -> Option<String> {
|
||||
if some {
|
||||
Some("Heyo".to_string())
|
||||
} else {None}
|
||||
extern {
|
||||
pub fn alert(s: &str);
|
||||
}
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn greet(name: &str) {
|
||||
alert(&format!("Hello, {}!", name));
|
||||
}
|
3389
ui/package-lock.json
generated
Normal file
3389
ui/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
8
ui/package.json
Normal file
8
ui/package.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"word_grid": "file:../pkg"
|
||||
},
|
||||
"devDependencies": {
|
||||
"parcel": "^2.9.3"
|
||||
}
|
||||
}
|
11
ui/src/index.html
Normal file
11
ui/src/index.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>hello-wasm example</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="./index.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
43
ui/src/index.js
Normal file
43
ui/src/index.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Use ES module import syntax to import functionality from the module
|
||||
// that we have compiled.
|
||||
//
|
||||
// Note that the `default` import is an initialization function which
|
||||
// will "boot" the module and make it ready to use. Currently browsers
|
||||
// don't support natively imported WebAssembly as an ES module, but
|
||||
// eventually the manual initialization won't be required!
|
||||
import init, { greet } from '../node_modules/word_grid/word_grid.js';
|
||||
|
||||
async function run() {
|
||||
// First up we need to actually load the wasm file, so we use the
|
||||
// default export to inform it where the wasm file is located on the
|
||||
// server, and then we wait on the returned promise to wait for the
|
||||
// wasm to be loaded.
|
||||
//
|
||||
// It may look like this: `await init('./pkg/without_a_bundler_bg.wasm');`,
|
||||
// but there is also a handy default inside `init` function, which uses
|
||||
// `import.meta` to locate the wasm file relatively to js file.
|
||||
//
|
||||
// Note that instead of a string you can also pass in any of the
|
||||
// following things:
|
||||
//
|
||||
// * `WebAssembly.Module`
|
||||
//
|
||||
// * `ArrayBuffer`
|
||||
//
|
||||
// * `Response`
|
||||
//
|
||||
// * `Promise` which returns any of the above, e.g. `fetch("./path/to/wasm")`
|
||||
//
|
||||
// This gives you complete control over how the module is loaded
|
||||
// and compiled.
|
||||
//
|
||||
// Also note that the promise, when resolved, yields the wasm module's
|
||||
// exports which is the same as importing the `*_bg` module in other
|
||||
// modes
|
||||
await init();
|
||||
|
||||
// And afterwards we can use all the functionality defined in wasm.
|
||||
greet("Heyo!");
|
||||
}
|
||||
|
||||
run();
|
Loading…
Reference in a new issue