Modified to use newer wasm-bindgen flow and web target

master
David O'Connor 5 years ago
parent f6b66468b7
commit 2980c62f9f

@ -23,6 +23,6 @@ futures = "^0.1.26"
wasm-bindgen-test = "0.2.45" # NOTE: keep in sync with wasm-bindgen version
[profile.release]
[profile.release] # Attempts to minimize file size
lto = true
opt-level = 'z'

@ -20,19 +20,24 @@ args = ["build", "--release"]
description = "Build with wasm-pack"
install_crate = { crate_name = "wasm-pack", binary = "wasm-pack", test_arg = "-V" }
command = "wasm-pack"
args = ["build", "--target", "no-modules", "--out-name", "package", "--dev"]
args = ["build", "--target", "web", "--out-name", "package", "--dev"]
[tasks.create_wasm_release]
description = "Build with wasm-pack"
install_crate = { crate_name = "wasm-pack", binary = "wasm-pack", test_arg = "-V" }
command = "wasm-pack"
args = ["build", "--target", "no-modules", "--out-name", "package"]
args = ["build", "--target", "web", "--out-name", "package"]
[tasks.build]
description = "Build, and create wasms"
workspace = false
dependencies = ["compile", "create_wasm"]
[tasks.build_release]
description = "Build, and create wasms, with the release flag"
workspace = false
dependencies = ["compile_release", "create_wasm_release"]
[tasks.watch]
description = "Build, create wasms, and watch/recompile files for changes"
workspace = false

@ -10,25 +10,15 @@
<title>A Title</title>
</head>
<body>
<section id="app"></section>
</head>
<script src='/pkg/package.js'></script>
<body>
<section id="app"></section>
<script type="module">
// https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html
import init from '/pkg/package.js';
init('/pkg/package_bg.wasm');
</script>
<script>
// the `wasm_bindgen` global is set to the exports of the Rust module
const { render } = wasm_bindgen;
// we'll defer our execution until the wasm is ready to go
function run() {
render();
}
// here we tell bindgen the path to the wasm file so it can run
// initialization and return to us a promise when it's done
wasm_bindgen('/pkg/package_bg.wasm')
.then(run)
.catch(console.error);
</script>
</body>
</body>
</html>

@ -41,7 +41,7 @@ fn view(model: &Model) -> impl View<Msg> {
]
}
#[wasm_bindgen]
#[wasm_bindgen(start)]
pub fn render() {
seed::App::build(|_, _| Model::default(), update, view)
.finish()

Loading…
Cancel
Save