Build tool for Leptos:
watch
command for automatic rebuilds with browser live-reload.test
command for running tests of the lib and bin packages that makes up the Leptos project.build
build the server and client.end2end
command for building, running the server and calling a bash shell hook. The hook would typically launch Playwright or similar.new
command for creating a new project based on templates, using cargo-generate. WIP: You'll need to ask on the Leptos discord for the url of a template.
Install:
cargo install --locked cargo-leptos
If you for any reason needs the bleeding-edge super fresh version:
cargo install --git https://github.com/akesson/cargo-leptos cargo-leptos
Help:
cargo leptos --help
For setting up your project, have a look at the examples
The single-package setup is where the code for both the frontend and the server is defined in a single package.
Configuration parameters are defined in the package Cargo.toml
section [package.metadata.leptos]
. See the Parameters reference for
a full list of parameters that can be used. All paths are relative to the package root (i.e. to the Cargo.toml
file)
When using a workspace setup both single-package and multi-package projects are supported. The latter is when the frontend and the server reside in different packages.
All workspace members whose Cargo.toml
define the [package.metadata.leptos]
section are automatically included as Leptos
single-package projects. The multi-package projects are defined on the workspace level in the Cargo.toml
's
section [[workspace.metadata.leptos]]
which takes three mandatory parameters:
```toml [[workspace.metadata.leptos]]
name = "leptos-project" bin-package = "server" lib-package = "front"
```
Note the double braces: several projects can be defined and one package can be used in several projects.
When building with cargo-leptos, the frontend, library package, is compiled into wasm using target
wasm-unknown-unknown
and the features --no-default-features --features=hydrate
The server binary is compiled with the features --no-default-features --features=ssr
These parameters are used either in the workspace section [[workspace.metadata.leptos]]
or the package,
for single-package setups, section [package.metadata.leptos]
.
```toml
#
bin-target = "my-bin-name"
#
bin-features = ["ssr"]
#
bin-default-features = false
#
lib-features = ["hydrate"]
#
lib-default-features = false ```
These parameters can be overridden by setting the corresponding environment variable. They can also be
set in a .env
file as cargo-leptos reads the first it finds in the package or workspace directory and
any parent directory.
```toml
#
output-name = "myproj"
#
site-root = "target/site"
#
site-pkg-dir = "pkg"
dart-sass
#
style-file = "style/main.scss"
#
browserquery = "defaults"
#
assets-dir = "assets"
#
site-addr = "127.0.0.1:3000"
#
reload-port = 3001
#
end2end-cmd = "npx playwright test"
#
end2end-dir = "integration" ```
The following environment variables are set when compiling the lib (front) or bin (server) and when the server is run.
Echoed from the Leptos config:
Directories used when building:
Note when using directories:
cargo-leptos
changes the working directory to the project root or if in a workspace, the workspace root before building and running.