Build tool for Leptos (Rust)

Overview

crates.io Discord

Build tool for Leptos:

Leptos Logo



Features

  • Parallel build of server and client in watch mode for fast developer feedback.

  • Build server and client for hydration (client-side rendering mode not supported).

  • Support for both workspace and single-package setup.

  • SCSS compilation using dart-sass.

  • CSS transformation and minification using Lightning CSS. See docs for full details.

  • Builds server and client (wasm) binaries using Cargo.

  • Generates JS - Wasm bindings with wasm-bindgen

  • Optimises the wasm with wasm-opt from Binaryen

  • Generation of rust code for integrating with a server of choice.

  • watch command for automatic rebuilds with browser live-reload.

  • test command for running tests. Note that this runs cargo test for the two different modes (hydrate and ssr).

  • 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.


Getting started

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


Single-package setup

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)


Workspace setup

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:

[[workspace.metadata.leptos]]
# project name
name = "leptos-project"
bin-package = "server"
lib-package = "front"

# more configuration parameters...

Note the double braces: several projects can be defined and one package can be used in several projects.


Build features

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


Parameters reference

These parameters are used either in the workspace section [[workspace.metadata.leptos]] or the package, for single-package setups, section [package.metadata.leptos].

Compilation parameters

# Sets the name of the binary target used.
#
# Optional, only necessary if the bin-package defines more than one target
bin-target = "my-bin-name"

# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]

# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false

# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]

# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false

Site parameters

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.

The environment variables are also provided by cargo-leptos when building, running and testing.

# Sets the name of the output js, wasm and css files.
#
# Optional, defaults to the lib package name or, in a workspace, the project name. Env: OUTPUT_NAME.
output-name = "myproj"

# The site root folder is where cargo-leptos generate all output.
# NOTE: It is relative to the workspace root when running in a workspace.
# WARNING: all content of this folder will be erased on a rebuild.
#
# Optional, defaults to "target/site". Env: LEPTOS_SITE_ROOT.
site-root = "target/site"

# The site-root relative folder where all compiled output (JS, WASM and CSS) is written.
#
# Optional, defaults to "pkg". Env: LEPTOS_SITE_PKG_DIR.
site-pkg-dir = "pkg"

# The source style file. If it ends with _.sass_ or _.scss_ then it will be compiled by `dart-sass`
# into CSS and processed by lightning css. When release is set, then it will also be minified.
#
# Optional. Env: LEPTOS_STYLE_FILE.
style-file = "style/main.scss"

# The browserlist https://browsersl.ist query used for optimizing the CSS.
#
# Optional, defaults to "defaults". Env: LEPTOS_BROWSERQUERY.
browserquery = "defaults"

# Assets source dir. All files found here will be copied and synchronized to site-root.
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
#
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "assets"

# The IP and port where the server serves the content. Use it in your server setup.
#
# Optional, defaults to 127.0.0.1:3000. Env: LEPTOS_SITE_ADDR.
site-addr = "127.0.0.1:3000"

# The port number used by the reload server (only used in watch mode).
#
# Optional, defaults 3001. Env: LEPTOS_RELOAD_PORT
reload-port = 3001

# The command used for running end-to-end tests.
#
# Optional. Env: LEPTOS_END2END_CMD.
end2end-cmd = "npx playwright test"

# The directory from which the end-to-end tests are run.
#
# Optional. Env: LEPTOS_END2END_DIR
end2end-dir = "integration"

Comments
  • Replace `binary-install`

    Replace `binary-install`

    Hello Henrik,

    when I do cargo leptos build -r I got:

        Finished release [optimized] target(s) in 18.61s
           Cargo finished cargo build --no-default-features --features=hydrate --lib --target=wasm32-unknown-unknown --release
    Error: at `src/main.rs@147:33`
    
    Caused by:
        0: at `src/main.rs@163:36`
        1: at `src/run/wasm.rs@20:34`
        2: at `src/run/wasm.rs@52:41`
        3: at `src/run/wasm.rs@77:35`
        4: Unable to download wasm-opt for macos aarch64 due to: failed to extract tarball from https://github.com/WebAssembly/binaryen/releases/download/version_111/binaryen-version_111-arm64-macos.tar.gz
    

    I installed the latest cargo-leptos, and without -r, the build woks.

    bug 
    opened by ebadta81 6
  • cargo leptos serve failes: Could not create

    cargo leptos serve failes: Could not create "/pkg/pkg"

    • cargo leptos new -g https://github.com/leptos-rs/start
    • cargo leptos watch
    Cargo finished cargo build --package=leptos-start --bin=leptos-start --target-dir=target/server --no-default-features --features=ssr
    Error: at `/Users/joep/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.1.0/src/command/serve.rs:8:42`
    
    Caused by:
        0: Could not create "/pkg/pkg" at `/Users/joep/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.1.0/src/ext/fs.rs:58:10`
        1: Read-only file system (os error 30)
    
    • cargo-leptos 0.1.0
    • rustc 1.67.0-nightly (85f4f41de 2022-11-08)
    • MacOS 13.1, m1 pro
    opened by joepio 5
  • missing field `metadata` for key `package` at line 13 column 1

    missing field `metadata` for key `package` at line 13 column 1

    Hi,

    cargo install --locked cargo-leptos, cargo-leptos init is ok, but when I try cargo-leptos serve or build, i get the missing field `metadata` for key `package` at line 13 column 1 error message.

    opened by ebadta81 4
  • Impossible to compile on fresh git clone

    Impossible to compile on fresh git clone

    The compiler leaves me this message:

    Compiling cargo-leptos v0.0.8 (C:\Users\Theo\Workspace\cargo-leptos) error[E0063]: missing fields filter and map in initializer of ExtractOpts --> src\ext\exe.rs:113:18 | 113 | &decompress::ExtractOpts { strip: 1 }, | ^^^^^^^^^^^^^^^^^^^^^^^ missing filter and map

    For more information about this error, try rustc --explain E0063. error: could not compile cargo-leptos due to previous error error: failed to compile cargo-leptos v0.0.8 (C:\Users\Theo\Workspace\cargo-leptos), intermediate artifacts can be found at

    Cargo version: cargo 1.68.0-nightly (70898e522 2022-12-05)

    opened by Kaporos 3
  • Windows: error auto-installing `dart-sass`

    Windows: error auto-installing `dart-sass`

    On windows, when running cargo leptos watch without sass installed:

    Leptos rebuild stopped due to error: at `src\main.rs@147:33`
    
    Caused by:
        0: at `src\main.rs@155:30`
        1: compile sass/scss: style/main.scss at `src\run\sass.rs@24:14`
        2: Try manually installing sass: https://sass-lang.com/install at `src\run\sass.rs@45:26`
        3: Unable to download sass for windows x86_64 due to: failed to download from https://github.com/sass/dart-sass/releases/download/1.56.1/dart-sass-1.56.1-windows-x64.zip
    

    The error is thrown by the binary-install crate.

    Preliminary investigation shows that the cache dir AppData/Local/.cargo-leptos is created, but nothing is extracted to it.

    Any help solving this would be appreciated as I don't have Windows myself.

    bug help wanted 
    opened by akesson 3
  • Issue installing `cargo-generate` on arm64 macos

    Issue installing `cargo-generate` on arm64 macos

    When I tried to run cargo leptos new --name example for the first time it gave me the error

    Error: Unable to download cargo-generate for macos x86_64 due to: failed to download from https://github.com/cargo-generate/cargo-generate/releases/download/0.17.3/cargo-generate-0.17.3-x86_64-apple-darwin.tar.gz

    I'm on arm64 macos. I was able to install cargo-generate manually using cargo install cargo-generate

    opened by gbj 3
  • Fix `cargo-generate` arguments and binary URL

    Fix `cargo-generate` arguments and binary URL

    • Link to download cargo-generate binaries had incorrect URL
      • This caused an issue when cargo-generate was not installed in PATH (via cargo install cargo-generate)
    • Arguments for cargo-generate
      • Missing generate argument (it's also needed when invoking the command from PATH ~/.cargo/bin/cargo-generate generate)
      • --name test should be send to ["--name", "test"]
    opened by michalvavra 2
  • cargo-leptos can't find sass binaries

    cargo-leptos can't find sass binaries

    I am using Windows 10 with rust nightly and this problem occurs with a fresh project created using "cargo leptos new --git https://github.com/leptos-rs/start"

    error

    I think it happens because the extracted content actually has a "dart-sass" folder instead of the sass binaries: folder The build process runs just fine if i move the files from the "dart-sass" folder to the sass folder folder2

    The same problem also occurs with "wasm-opt-version_111" when building the project

    opened by msmaiaa 1
  • `binary-install` replacement, resolves #24

    `binary-install` replacement, resolves #24

    Intial implementation. I've tested it on Windows 11 only (no macOS and Linux yet). But I'm fairly confident it will work fine.

    I found a new crate decompress for extracting archives. I struggled to find any other good alternative.

    In works fine but I'm not happy with the code yet. Hopefully in couple of days the PR will be ready.

    Any feedback is appriciated!

    opened by michalvavra 1
  • use git dependency

    use git dependency

    This is a temporary fix as it is probably not a good idea to track the main branch. But I assume it will be fixed shortly? In any case this makes cargo-leptos work on my machine.

    opened by ptillemans 1
  • Add i18n

    Add i18n

    Possibly integrating with:

    • Fluent: The core translation syntax.
    • cargo i18n: This crate is a Cargo sub-command cargo i18n which can be used to extract and build, and verify localization resources at compile time for your crate.
    • Rust I18n: Rust I18n is a crate for loading localized text from a set of YAML mapping files. The mappings are converted into data readable by Rust programs at compile time, and then localized text can be loaded by simply calling the provided t! macro.

    WIP: This needs further investigation.

    enhancement 
    opened by akesson 1
  • Running `cargo leptos build` on a new project fails

    Running `cargo leptos build` on a new project fails

    I'm having the following issue when running cargo leptos build:

     Compiling leptos_router v0.0.6 (https://github.com/gbj/leptos#0b448daf)
    error[E0554]: `#![feature]` may not be used on the stable release channel
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:141:38
        |
    141 | #![cfg_attr(not(feature = "stable"), feature(auto_traits))]
        |                                      ^^^^^^^^^^^^^^^^^^^^
    
    error[E0554]: `#![feature]` may not be used on the stable release channel
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:142:38
        |
    142 | #![cfg_attr(not(feature = "stable"), feature(negative_impls))]
        |                                      ^^^^^^^^^^^^^^^^^^^^^^^
    
    error[E0554]: `#![feature]` may not be used on the stable release channel
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:143:38
        |
    143 | #![cfg_attr(not(feature = "stable"), feature(type_name_of_val))]
        |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^
    
    error[E0554]: `#![feature]` may not be used on the stable release channel
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:143:46
        |
    143 | #![cfg_attr(not(feature = "stable"), feature(type_name_of_val))]
        |                                              ^^^^^^^^^^^^^^^^
    
    error[E0277]: expected a `FnMut<()>` closure, found `leptos::Memo<std::option::Option<leptos::Child>>`
      --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/routes.rs:31:49
       |
    31 | pub fn Routes(cx: Scope, props: RoutesProps) -> impl IntoChild {
       |                                                 ^^^^^^^^^^^^^^ expected an `FnMut<()>` closure, found `leptos::Memo<std::option::Option<leptos::Child>>`
       |
       = help: the trait `FnMut<()>` is not implemented for `leptos::Memo<std::option::Option<leptos::Child>>`
       = note: wrap the `leptos::Memo<std::option::Option<leptos::Child>>` in a closure with no arguments: `|| { /* code */ }`
       = help: the trait `leptos::IntoChild` is implemented for `leptos::Memo<Vec<web_sys::Element>>`
       = note: required for `leptos::Memo<std::option::Option<leptos::Child>>` to implement `leptos::IntoChild`
    
    error[E0599]: the method `into_attribute` exists for struct `leptos::Memo<std::option::Option<std::string::String>>`, but its trait bounds were not satisfied
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/form.rs:146:21
        |
    146 |                     action=action
        |                     ^^^^^^ method cannot be called on `leptos::Memo<std::option::Option<std::string::String>>` due to unsatisfied trait bounds
        |
       ::: /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/leptos_reactive/src/memo.rs:118:1
        |
    118 | pub struct Memo<T>(pub(crate) ReadSignal<Option<T>>)
        | ------------------
        | |
        | doesn't satisfy `<_ as FnOnce<()>>::Output = _`
        | doesn't satisfy `_: leptos::IntoAttribute`
        | doesn't satisfy `_: std::ops::Fn<()>`
        |
        = note: the following trait bounds were not satisfied:
                `<leptos::Memo<std::option::Option<std::string::String>> as FnOnce<()>>::Output = _`
                which is required by `leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
                `leptos::Memo<std::option::Option<std::string::String>>: std::ops::Fn<()>`
                which is required by `leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
                `<&leptos::Memo<std::option::Option<std::string::String>> as FnOnce<()>>::Output = _`
                which is required by `&leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
                `&leptos::Memo<std::option::Option<std::string::String>>: std::ops::Fn<()>`
                which is required by `&leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
                `<&mut leptos::Memo<std::option::Option<std::string::String>> as FnOnce<()>>::Output = _`
                which is required by `&mut leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
                `&mut leptos::Memo<std::option::Option<std::string::String>>: std::ops::Fn<()>`
                which is required by `&mut leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
    
    error[E0631]: type mismatch in closure arguments
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/form.rs:148:31
        |
    68  |     let on_submit = move |ev: web_sys::SubmitEvent| {
        |                     ------------------------------- found signature defined here
    ...
    148 |                     on:submit=on_submit
        |                     --        ^^^^^^^^^ expected due to this
        |                     |
        |                     required by a bound introduced by this call
        |
        = note: expected closure signature `fn(Event) -> _`
                   found closure signature `fn(SubmitEvent) -> _`
    note: required by a bound in `add_event_listener`
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/leptos_dom/src/operations.rs:290:22
        |
    290 |             cb: impl FnMut(web_sys::Event) + 'static,
        |                      ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `add_event_listener`
    
    error[E0631]: type mismatch in closure arguments
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/form.rs:318:23
        |
    288 |     let on_submit = move |ev: web_sys::SubmitEvent| {
        |                     ------------------------------- found signature defined here
    ...
    318 |             on:submit=on_submit
        |             --        ^^^^^^^^^ expected due to this
        |             |
        |             required by a bound introduced by this call
        |
        = note: expected closure signature `fn(Event) -> _`
                   found closure signature `fn(SubmitEvent) -> _`
    note: required by a bound in `add_event_listener`
       --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/leptos_dom/src/operations.rs:290:22
        |
    290 |             cb: impl FnMut(web_sys::Event) + 'static,
        |                      ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `add_event_listener`
    
    Some errors have detailed explanations: E0277, E0554, E0599, E0631.
    For more information about an error, try `rustc --explain E0277`.
    error: could not compile `leptos_router` due to 8 previous errors
           Cargo build failed
    Error: at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/main.rs@147:33`
    
    Caused by:
        0: at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/main.rs@163:36`
        1: at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/run/wasm.rs@20:34`
        2: cargo build --no-default-features --features=hydrate --lib --target=wasm32-unknown-unknown at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/run/cargo.rs@21:10`
        3: Process exited with code exit status: 101
        ```
    
    I'm new to Rust and I know leptos is in it's early stages, but maybe somebody could tell me what I'm doing wrong. I can share whatever code or configuration you'll need, but my Cargo.toml is exactly the same than the example project.
    opened by Gorzas 2
Releases(0.0.5)
Owner
henrik
henrik
Tauri and Leptos example.

tauri-leptos-example Tauri Leptos Requires Rust Nightly. See Leptos nightly Note. # Install Tauri CLI cargo install tauri-cli # Build and develop for

Michal Vavra 5 Dec 6, 2022
Tool written in rust to read for file changes and accordingly run build commands.

Sniff A simple tool written in rust to read for file changes and accordingly run build commands. Note this tool is for linux and linux only. If it hap

Aakash Sen Sharma 4 Oct 2, 2022
🦞 wasm-pack based build tool

rsw-rs This project is in early experimental stage. # dev rsw watch # release rsw build # create crate rsw new # rsw.toml name = 'rsw' version = "0.

lencx 71 Dec 30, 2022
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion 1 Oct 19, 2021
Automatically build a Rust module tree from the project directory structure

Hypermod An even lazier version of automod and supermod. Searches the src/ directory recursively for .rs files, then builds a module tree using the di

null 4 Aug 3, 2022
A code generator to reduce repetitive tasks and build high-quality Rust libraries. 🦀

LibMake A code generator to reduce repetitive tasks and build high-quality Rust libraries Welcome to libmake ?? Website • Documentation • Report Bug •

Sebastien Rousseau 27 Mar 12, 2023
Build and deploy cross platform bioinformatic utilities with Rust.

The Bioinformatics Toolkit RUST-backed utilities for bioinformatic data processing. Get started The fastest way to get started it to download the appl

null 5 Sep 8, 2023
dark-std an Implementation of asynchronous containers build on tokio

dark-std dark-std is an Implementation of asynchronous containers build on tokio. It uses a read-write separation design borrowed from Golang SyncHash

darkrpc 4 Dec 13, 2022
Build your service-server fast, easy (and without hosting!)

service-io is a library to build servers that offering services with really little effort. Choose an input connector. Choose an output connector. Choo

Luis Enrique Muñoz Martín 34 Jan 4, 2023
Cargo extension to recycle outdated build artifacts

cargo gc Cargo extension to recycle outdated build artifacts. And try the best to avoid recompilation. Usage Install it with cargo: cargo install carg

Ruihang Xia 23 Aug 30, 2023
Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code

Diplomat is an experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code. With Diplomat, you can simply define Rust APIs to be exposed over FFI and get high-level C, C++, and JavaScript bindings automatically!

null 255 Dec 30, 2022
A command-line tool collection to assist development written in RUST

dtool dtool is a command-line tool collection to assist development Table of Contents Description Usage Tips Installation Description Now dtool suppor

GB 314 Dec 18, 2022
Keyscope is a key and secret workflow (validation, invalidation, etc.) tool built in Rust

✅ Automate your key and secret validation workflows ?? Over 30 different providers ?? Export to JSON, audit via CSV ?? Keyscope Keyscope is a key and

null 364 Dec 22, 2022
The tool like Browserslist, but written in Rust.

browserslist-rs The tool like Browserslist, but written in Rust. Try it out Before trying this crate, you're required to get Rust installed. Then, clo

Pig Fang 76 Nov 29, 2022
A code coverage tool for Rust projects

Tarpaulin Tarpaulin is a code coverage reporting tool for the Cargo build system, named for a waterproof cloth used to cover cargo on a ship. Currentl

null 1.8k Jan 2, 2023
A Rust-based tool to analyze an application's heap.

Heap analysis tool for Rust Heap analysis is a pure-Rust implementation to track memory allocations on the heap. Usage Heap analysis provides a custom

Moritz Hoffmann 8 May 9, 2022
Fast, compact and all-around subdomain enumeration tool written in Rust

Fast, compact and all-around subdomain enumeration tool written in Rust, which uses dns bruteforce, internet search and recursive http content search.

foreseon 16 Dec 10, 2022
A tool of generating and viewing dice roll success distributions.

AZDice A GUI tool for generating and visualising dice roll probability distributions. Aims Intended to help people trying to get game balance just rig

null 13 Mar 2, 2021
Simple tool for scaffolding

quick-skeleton tldr; Lightweight replacement for yeoman or slush. Powered by handlebars. This is a scaffolding tool to save you hours of writing boile

Arthur 23 Apr 21, 2022