Skill v1.0.0
currentAutomated scan100/100name: cargo-leptos-config description: Configure cargo-leptos via [package.metadata.leptos] or [[workspace.metadata.leptos]]. Auto-triggers when adding/modifying Cargo.toml metadata for a Leptos project, changing site-addr/style/assets, or debugging cargo leptos build failures. metadata: version: "1.0.0"
Cargo-Leptos Config
When to Use
Invoke before:
- Adding
[package.metadata.leptos]to a new project. - Adding
[[workspace.metadata.leptos]]to a workspace with multiple Leptos apps. - Changing
site-addr,style-file,tailwind-input-file,assets-dir, or feature sets. - Debugging
cargo leptos build/cargo leptos watchfailures related to config. - Switching from Trunk (CSR-only) to cargo-leptos (SSR+hydrate).
Note: CSR-only apps are NOT supported under cargo-leptos. Use Trunk for CSR.
Core Patterns
Pattern 1 — Single-Package Metadata Block
For single-crate Leptos projects (no workspace). Placed in the root Cargo.toml.
[package]name = "my_app"version = "0.1.0"edition = "2021"[package.metadata.leptos]# Requiredoutput-name = "my_app"# Buildbin-features = ["ssr"]lib-features = ["hydrate"]bin-default-features = false # IMPORTANT: opposite of Cargo defaultlib-default-features = false # IMPORTANT: opposite of Cargo default# Dev serversite-addr = "127.0.0.1:3000"# Output pathssite-root = "target/site"site-pkg-dir = "pkg"# Assetsassets-dir = "public"style-file = "style/main.scss"# Testingend2end-cmd = "npx playwright test"end2end-dir = "end2end"
Anti-pattern — omitting bin/lib-default-features:
# BAD: without bin-default-features = false, cargo-leptos enables ALL default# features for the binary — e.g., client-side wasm deps leak into SSR binary.[package.metadata.leptos]output-name = "my_app"# bin-default-features missing → defaults to false, but leaving it out# makes it unclear to reviewers. Always state explicitly.
Pattern 2 — Workspace Array-of-Tables
For workspaces with multiple Leptos apps. Uses [[workspace.metadata.leptos]] (array of tables). Each entry requires name, bin-package, lib-package.
# Cargo.toml (workspace root)[[workspace.metadata.leptos]]name = "admin"bin-package = "admin-server"lib-package = "admin-ui"output-name = "admin"site-addr = "127.0.0.1:3001"bin-features = ["ssr"]lib-features = ["hydrate"]bin-default-features = falselib-default-features = falsestyle-file = "admin-ui/style/main.scss"assets-dir = "admin-ui/public"[[workspace.metadata.leptos]]name = "storefront"bin-package = "storefront-server"lib-package = "storefront-ui"output-name = "storefront"site-addr = "127.0.0.1:3002"bin-features = ["ssr"]lib-features = ["hydrate"]bin-default-features = falselib-default-features = false
Anti-pattern — using [workspace.metadata.leptos] (single table) in a workspace:
# BAD: single-table form is for [package.metadata.leptos] only.# Workspaces MUST use [[workspace.metadata.leptos]] (double-bracket array).[workspace.metadata.leptos] # ← wrong form for workspacesname = "my_app"
Pattern 3 — Tailwind Integration
When using Tailwind CSS, provide both tailwind-input-file and tailwind-config-file. cargo-leptos runs the Tailwind CLI automatically on cargo leptos watch.
[package.metadata.leptos]output-name = "my_app"tailwind-input-file = "style/input.css"tailwind-config-file = "tailwind.config.js"# Do NOT also set style-file when using tailwind — pick onebin-features = ["ssr"]lib-features = ["hydrate"]bin-default-features = falselib-default-features = false
Anti-pattern — setting both style-file and tailwind-input-file:
# BAD: ambiguous — cargo-leptos behaviour is undefined when both are present.style-file = "style/main.scss"tailwind-input-file = "style/input.css" # ← conflict
Pattern 4 — Custom Server-Fn Prefix
The server-fn-prefix key controls the HTTP path prefix used for all #[server] fn routes. Default is /api. Must match the Axum mount point.
[package.metadata.leptos]output-name = "my_app"server-fn-prefix = "/api/v1" # all server fns mount under /api/v1bin-features = ["ssr"]lib-features = ["hydrate"]bin-default-features = falselib-default-features = false
// Axum main.rs — prefix must match cargo-leptos configlet routes = generate_route_list(App);let router = Router::new().leptos_routes_with_context(&leptos_options, routes, provide_context_fn, shell).with_state(state);
Anti-pattern — mismatch between config prefix and axum mount:
// BAD: config says /api/v1 but axum mounts at /api → 404 on all server fnsRouter::new().nest("/api", server_fn_routes) // ← doesn't match /api/v1
Anti-Patterns to Block
- Using
cargo leptosfor a CSR-only app → switch to Trunk; cargo-leptos does not support CSR. - Missing
name/bin-package/lib-packagein workspace array entry → all three are required. bin-default-featuresorlib-default-featuresnot set tofalse→ always set explicitly to avoid leaking features across targets.[[workspace.metadata.leptos]]entries with identicalsite-addr→ each app must bind a distinct port.style-fileandtailwind-input-fileboth set → pick exactly one CSS pipeline.server-fn-prefixin config not matching the Axum router mount → mismatched prefix causes silent 404s on all server fns.js-dirchanged without moving actual JS files → cargo-leptos will silently fail to bundle JS.
Verification Hooks
# Confirm metadata block existsgrep -n 'metadata.leptos' Cargo.toml# Confirm bin/lib-default-features are both falsegrep -n 'default-features' Cargo.toml# Confirm server-fn-prefix matches the Axum mountgrep -rn 'server-fn-prefix' Cargo.tomlgrep -rn 'nest\|leptos_routes' src/# Dry-run build to catch config errors before watchingcargo leptos build 2>&1 | head -40# List all registered leptos projects in workspacecargo leptos list 2>/dev/null || true
References
- https://github.com/leptos-rs/cargo-leptos (README — full key reference)
- https://book.leptos.dev/deployment/cargo_leptos.html
- https://docs.rs/cargo-leptos