6b90e1babd | ||
---|---|---|
.. | ||
public | ||
src | ||
.gitignore | ||
Cargo.toml | ||
LICENSE | ||
Makefile.toml | ||
README.md |
README.md
Leptos Counter Isomorphic Example
This example demonstrates how to use a function isomorphically, to run a server side function from the browser and receive a result.
Client Side Rendering
For this example the server must store the counter state since it can be modified by many users. This means it is not possible to produce a working CSR-only version as a non-static server is required.
Server Side Rendering with cargo-leptos
cargo-leptos is now the easiest and most featureful way to build server side rendered apps with hydration. It provides automatic recompilation of client and server code, wasm optimisation, CSS minification, and more! Check out more about it here
- Install cargo-leptos
cargo install --locked cargo-leptos
- Build the site in watch mode, recompiling on file changes
cargo leptos watch
Open browser on http://localhost:3000/
- When ready to deploy, run
cargo leptos build --release
Server Side Rendering without cargo-leptos
To run it as a server side app with hydration, you'll need to have wasm-pack installed.
- Edit the
[package.metadata.leptos]
section and setsite-root
to"."
. For examples with CSS you also want to change the path of the<StyleSheet / >
component in the root component to point towards the CSS file in the root. This tells leptos that the WASM/JS files generated by wasm-pack are available at./pkg
and that the CSS files are no longer processed by cargo-leptos. Building to alternative folders is not supported at this time. You'll also want to edit the call toget_configuration()
to pass inSome(Cargo.toml)
, so that Leptos will read the settings instead of cargo-leptos. If you do so, your file/folder names cannot include dashes. - Install wasm-pack
cargo install wasm-pack
- Build the Webassembly used to hydrate the HTML from the server
wasm-pack build --target=web --debug --no-default-features --features=hydrate
- Run the server to serve the Webassembly, JS, and HTML
cargo run --no-default-features --features=ssr