examples/SSR_NOTES.md
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
cargo install --locked cargo-leptos
cargo leptos watch
Open browser on http://localhost:3000/
cargo leptos build --release
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 set site-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 to get_configuration() to pass in Some(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
wasm-pack build --target=web --debug --no-default-features --features=hydrate
cargo run --no-default-features --features=ssr
To run it as a server side app with hydration, first you should run
wasm-pack build --target=web --debug --no-default-features --features=hydrate
to generate the WebAssembly to hydrate the HTML delivered from the server.
Then run the server with cargo run to serve the server side rendered HTML and the WASM bundle for hydration.
cargo run --no-default-features --features=ssr
Note that if your hydration code changes, you will have to rerun the wasm-pack command above before running
cargo run