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 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 lto = true
opt-level = 'z' opt-level = 'z'

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

@ -11,23 +11,13 @@
<title>A Title</title> <title>A Title</title>
</head> </head>
<body> <body>
<section id="app"></section> <section id="app"></section>
<script type="module">
<script src='/pkg/package.js'></script> // https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html
import init from '/pkg/package.js';
<script> init('/pkg/package_bg.wasm');
// 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> </script>
</body> </body>

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

Loading…
Cancel
Save