2023-01-01 00:06:54 +00:00
# Leptos Todo App Sqlite
2022-11-18 18:25:12 +00:00
2023-01-01 00:06:54 +00:00
This example creates a basic todo app with an Axum backend that uses Leptos' server functions to call sqlx from the client and seamlessly run it on the server.
2022-11-18 18:25:12 +00:00
2023-01-01 00:06:54 +00:00
## Client Side Rendering
To run it as a Client Side App, you can issue `trunk serve --open` in the root. This will build the entire
app into one CSR bundle. Make sure you have trunk installed with `cargo install trunk` .
2022-11-30 01:00:09 +00:00
2023-01-01 00:06:54 +00:00
## 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 ](https://github.com/akesson/cargo-leptos )
2022-11-30 01:00:09 +00:00
2023-01-01 00:06:54 +00:00
1. Install cargo-leptos
2022-11-18 18:25:12 +00:00
```bash
2023-01-01 00:06:54 +00:00
cargo install --locked cargo-leptos
```
2. Build the site in watch mode, recompiling on file changes
```bash
cargo leptos watch
```
3. When ready to deploy, run
```bash
cargo leptos build --release
2022-11-18 18:25:12 +00:00
```
2022-11-30 01:00:09 +00:00
2023-01-01 00:06:54 +00:00
## Server Side Rendering without cargo-leptos
To run it as a server side app with hydration, you'll need to have wasm-pack installed.
0. Edit the `[package.metadata.leptos]` section and set `site-root` to `"pkg"` . This tells leptos that the WASM/JS files generated by wasm-pack
are available at `./pkg` . Building to alternative folders is not supported at this time
1. Install wasm-pack
```bash
cargo install wasm-pack
```
2. Build the Webassembly used to hydrate the HTML from the server
```bash
wasm-pack build --target=web --debug --no-default-features --features=hydrate
```
3. Run the server to serve the Webassembly, JS, and HTML
2022-11-18 18:25:12 +00:00
```bash
2023-01-01 00:06:54 +00:00
cargo run --no-default-features --features=ssr
2022-11-18 18:25:12 +00:00
```
2022-11-30 01:00:09 +00:00