This is a template for use with the Leptos web framework and the cargo-leptos tool using leptos_wasi.
cargo install cargo-leptos --locked
cargo install cargo-generate
cargo leptos new --git https://github.com/leptos-rs/start-wasi
You MUST write the serve_static_files
function in
src/server.rs
.
We make no assumptions about which world is available for your component. It is not guaranteed that you will give filesystem access to your component. That's why you need to explicitly write the logic to serve static files.
If you do want to use wasi:filesystem
, then you can check the link
in the comments of the said function. In the future, we may add default
implementation in leptos_wasi
to ease your life.
cargo leptos build --release
cargo leptos build
Well, by nature, WebAssembly give you the freedom to chose the runtime you want.
For now, we have only tested running the commponents with Wasmtime:
wasmtime serve {{component_outdir}}/wasm32-wasip2/debug/{{crate_name}}.wasm -Scli
Be sure to add the flags you need to provide the worlds your component depends on:
--dir target/site/pkg
if you want, for example, to usewasi:filesystem
to serve the static assets,--env
if you want to pass environment variables,
This template itself is released under the Unlicense. You should replace the LICENSE for your own application with an appropriate license if you plan to release it publicly.