Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

benwis/leptos-heavy-metal-stack

Repository files navigation

Heavy Metal Stack

Leptos stack with Axum, TailwindCSS, and Sqlite

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. It has an sqlite DB and can be run with cargo leptos

This starter uses git versions of leptos and the leptos packages because the framework is still moving quickly. There's a chance this is ahead of the current release, and that is intended. If it's behind git, feel free to open a PR or submit an issue.

Install Cargo Leptos

cargo install --locked cargo-leptos

Install TailwindCSS

See instructions here.

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

  1. Build the Tailwind CSS
npx tailwindcss -i styles/input.css -o src/styles/output.css --watch
  1. Install cargo-leptos
cargo install --locked cargo-leptos
  1. Build the site in watch mode, recompiling on file changes
cargo leptos watch
  1. 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.

  1. Edit the [package.metadata.leptos] section and set site-root to "pkg". You'll 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.
  2. Install wasm-pack
cargo install wasm-pack
  1. Build the Webassembly used to hydrate the HTML from the server
wasm-pack build --target=web --debug --no-default-features --features=hydrate
  1. Run the server to serve the Webassembly, JS, and HTML
cargo run --no-default-features --features=ssr

Sources

Setup Tailwind using the instructions from here: leptos-rs/leptos#125

About

Heavy Metal Leptos Stack with Tailwind, Axum, Sqlite, and Cargo Leptos

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published