This is a template project for Leptos apps, using TailwindCSS for styling and Nix for packaging and environments.
This repository is built to be used with Nix. If you don't have Nix installed, go here to install it. In short, Nix is a package manager built for reproducible builds and immutability. This repository should be perfectly usable without Nix, but if you attempt to use it without Nix you should be familiar with installing the necessary tools because I won't go over all the non-Nix instructions.
If you have direnv
installed, simply direnv allow
, and after some minutes you'll have your dev environment. If not, you can use nix develop
to do the same thing (assuming you've set up flakes and the new command syntax)
To start developing, simply run just
if you have just
installed. Otherwise, you can look in the justfile
file to find the commands (in this case it's the default recipe, run
, which is cargo leptos watch
).
If you'd like to test the release version of the app, run just serve
(cargo leptos serve --release
).
If you'd like to build and run the container version of the app, run just container
. This will build the container entirely in Nix, load it into the docker daemon, and run it ephemerally (--rm
) with port 3000 open. The image has correct defaults for all the environment variables that cargo-leptos
normally provides, but they're also overridable when you run the container.
To learn more about building containers in Nix, read here (tl;dr: it's awesome).
To just build and load the docker image, run nix build "./#container" && docker load -i result
. The image will be loaded with the label site-server
. You can then do any normal container action with this image.
You can also build the release build with nix build
(which builds the default package, site-server
), but if you run it with ./result/bin/site-server
, the binary won't inherit the environment variables that cargo-leptos
normally provides, which is why I recommend you just use the container.
crates/
: contains all the Rust cratessite-app/
: contains all the app code, isolated from its usagesrc/
lib.rs
: the app code, which defines<App/>
style/
: contains styles used by<App/>
main.scss
: the tailwind css input file, containing the@tailwind
directivestailwind/
: tailwind-specific filespackage.json
: JS manifest in case you need JS packages for your tailwind plugins (like DaisyUI)yarn.lock
: lock file for package.jsontailwind.config.js
: tailwind confignode_modules
: contains installed packages used to build tailwind plugins (ignored)
public/
: files here will be statically servedfavicon.ico
: the site icon
Cargo.toml
: the cargo manifest forsite-app
site-server/
: binary crate for serving the appsrc/
main.rs
: starts the axum serverfileserv.rs
: serve static files
Cargo.toml
: the cargo manifest forsite-server
site-frontend/
: stub crate for use withwasm-bindgen
src/
main.rs
: starts the axum serverfileserv.rs
: serve static files
Cargo.toml
: the cargo manifest forsite-server
.envrc
:direnv
commands to automatically set up the environment.gitignore
: git ignore fileCargo.lock
: cargo manifest lock fileCargo.toml
: cargo manifest file, which also contains leptos configurationflake.lock
: nix flake lock fileflake.nix
: nix flake filejustfile
: just recipe file