Writing a WebAssembly application using Yew
In the application, we are going to use Yew (https://yew.rs). On the website, it says that Yew is a modern Rust framework for creating multithreaded frontend web apps.
Cargo can compile the WebAssembly binary, but the WebAssembly binary itself is not usable without other steps. We have to load the WebAssembly binary in the web browser's virtual machine engine. There are proposals such as using a <script type="module"></script>
tag, but unfortunately, those proposals are not standard yet. We have to tell JavaScript to load the module using the WebAssembly Web API. To make the development easier, we can use wasm-pack
from the Rust WebAssembly working group at https://rustwasm.github.io/. Yew uses an application named trunk
(https://trunkrs.dev) that wraps wasm-pack
and provides other conveniences. Install trunk
by using this command:
cargo install --locked trunk
Now that the preparation for compiling WebAssembly...