STATUS: Local development of a Leptos-Shuttle project is working; however, Shuttle.rs IS NOT working for cloud deploys of Leptos apps. Contributions & fixes are welcome.
Note: This Leptos starter template has been modified to deploy to Shuttle.rs
For further details and for updates, see here: shuttle-hq/shuttle#1002 (comment)
This is a template for use with the Leptos web framework and the cargo-leptos tool using Axum.
If you don't have cargo-leptos installed you can install it with
cargo install cargo-leptosIf you don't have cargo-generate installed already, install it with
cargo install cargo-generateThen run
cargo generate --git https://github.com/Rust-WASI-WASM/shuttle-leptos-axum.gitCurrently, to run Leptos Shuttle locally, you must run in --release mode
to generate a new project template. Then
cd {{project-name}}to go to your newly created project.
Feel free to explore the project structure, but the best place to start with your application code is in src/app.rs.
Addtionally, Cargo.toml may need updating as new versions of the dependencies are released, especially if things are not working after a cargo update.
By default, cargo-leptos uses nightly Rust, cargo-generate, and sass. If you run into any trouble, you may need to install one or more of these tools.
rustup toolchain install nightly --allow-downgrade- make sure you have Rust nightlyrustup target add wasm32-unknown-unknown- add the ability to compile Rust to WebAssemblycargo install cargo-generate- installcargo-generatebinary (should be installed automatically in future)npm install -g sass- installdart-sass(should be optional in future)
First, make sure you have the Shuttle.rs CLI: run
cargo install cargo-shuttleto install the Shuttle CLI. Then, to log in to Shuttle, run
cargo shuttle loginWhen the Shuttle webpage opens, copy the API key and enter it into the Shuttle CLI.
In your project folder, run
cargo shuttle project startto initiate your new project with Shuttle. At this point, you can either run your project locally using the command
cargo shuttle run --releaseNB: cargo shuttle run by itself does not work - release mode must be used.
Or you can deploy to Shuttle.rs manually using the command
cargo leptos build --release && cargo shuttle deployNote: If you update the dependencies of your project, you'll need to re-initiate your Shuttle project using
cargo shuttle project restartIf you find that your deployed project does not look like it's updating, you may need to run the following commands in your project folder:
cargo clean
cargo leptos build --release && cargo shuttle deploycargo shuttle run --releaseWhile Shuttle's normal dev workflow can be run with cargo shuttle run, currently, to run Leptos Shuttle locally, you must run in --release mode to bypass issues with hydration.
Note: Shuttle.rs does not officially support Leptos in SSR mode. As of now, the following instructions DO NOT lead to a working Leptos SSR deploy to Shuttle.rs. You are welcome to make any contributions that will help remedy this issue.
cargo leptos build --releaseWill generate your server binary in target/server/release and your site package in target/site, and
cargo shuttle deploywill deploy your updated application to Shuttle.rs.
cargo leptos end-to-endcargo leptos end-to-end --releaseCargo-leptos uses Playwright as the end-to-end test tool. Tests are located in end2end/tests directory.