| Crates.io | leptos_forge_build_script |
| lib.rs | leptos_forge_build_script |
| version | 0.6.3 |
| created_at | 2025-10-24 08:28:06.542533+00 |
| updated_at | 2025-10-27 13:40:45.342762+00 |
| description | Small general purpose utility from leptos_forge project |
| homepage | https://mskorkowski.github.io/ |
| repository | https://github.com/mskorkowski/leptos-forge |
| max_upload_size | |
| id | 1898157 |
| size | 75,946 |
Library to be used in your build scripts for
cargo_resources for pulling resources from upstream crates without include_bytes!In your Cargo.toml add
[build-dependencies]
leptos_forge_build_script = "0.6"
In your build script:
use leptos_forge_build_script::console::{
Console,
ConsoleConfiguration,
};
fn main() {
let console_configuration = ConsoleConfiguration::default();
let console = Console::new("crate_name", &console_configuration);
console.info(&"This is an info message");
let x = 3;
console.warn(&format!("The x = {x}"));
}
Assuming your tailwind css files are located in assets/css/lib.css (relative to
respective Cargo.toml)
In your library crate Cargo.toml add (you don't need to depend on the leptos_forge_build_script here)
[package]
include=[
"src",
"assets"
]
[package.metadata.leptos_forge.tailwind]
# Path to the main tailwind file for your crate
#
# Lib is the tailwind `main.css` without `@import "tailwind"`. import "tailwind"
# statement will be added for you automatically.
lib="assets/css/lib.css"
In your application Cargo.toml add
[build-dependencies]
cargo_metadata="0.22.0"
leptos_forge_build_script = "0.6"
[package.metadata.leptos_forge.tailwind]
# Path to the main tailwind file for your crate
#
# Lib is the tailwind `main.css` without `@import "tailwind"`. import "tailwind"
# statement will be added for you automatically.
lib="assets/css/lib.css"
# Path where the compiled css file should be
output="target/resources/css/main.css"
In your application build script add
use std::env::current_dir;
use cargo_metadata::{
CargoOpt,
Metadata,
MetadataCommand,
camino::Utf8PathBuf,
}
use leptos_forge_build_script::{
console::{
Console,
ConsoleConfiguration,
},
tailwind::Tailwind,
};
fn main() {
// Setup printing messages to the console
let console_configuration = ConsoleConfiguration::default();
let console = Console::new("crate_name", &console_configuration);
// Read the cargo manifest
let cwd = current_dir().unwrap();
let manifest_file = Utf8PathBuf::from_path_buf(cwd).unwrap().join("Cargo.toml");
let mut metadata_cmd = MetadataCommand::new();
let metadata: Metadata = metadata_cmd
.manifest_path(&manifest_file)
.features(CargoOpt::AllFeatures)
.exec()
.unwrap();
{
// All output from the tailwind integration will have a `[tailwind]` tag prepended
let console = console.stage("tailwind");
// Run tailwind integration
//
//
let _output_path = Tailwind::new(
metadata,
&console,
// Override to any path you wish the main tailwind file should be generated
// by default it's placed under the path created using algorithm below
//
// 1. `OUT_DIR` env variable
// 2. To the path from `1` append `leptos_forge/build_script/tailwind`
// to make it separate from the rest of the output
//
None,
// If set to `true` it generates `cargo::rerun-if-changed=` statements
// for the local files (same workspace) scanned by tailwind.
//
// watching behavior can be fine tuned in your Cargo.toml
// `package.metadata.leptos_forge.tailwind.watch` configuration
true
).
run().
unwrap();
}
}
[!NOTE]
Setting the fourth argument of
Tailwind::newtotruemakes theleptos_forge_build_scriptgeneratecargo::rerun-if-changed=statements, which disables the default build script behavior. Depending on your other use cases it might require to adjust your build script behavior.Cargo defaults can be brought back by adding
std::println!("cargo::rerun-if-changed=.")
[package.metadata.leptos_forge.tailwind]
lib="relative/path/to/lib.css"
output="relative/path/to/target/result.css"
watch=[]
lib - relative path to the tailwind configuration for this crate. This file will be imported from the generated tailwindcss file
output - optional, relative path to the output of the tailwindcss
watch - optional, list of paths which will be passed to
cargo::rerun-if-changed=PATH relative to the crate Cargo.toml. If nonempty
it will override the automatic path discovery.
By default two paths are added:
lib.rs of the upstream cratelib tailwind configuration optionThe defaults are conservative and probably overly broad.
Resource provisioning in the build_script is a thin wrapper around the cargo_resources
itself.
First step is to setup your crates Cargo.toml as described in the cargo-resources documentation.
In your build script
use leptos_forge_build_script::{
console::{
Console,
ConsoleConfiguration,
},
resources::Resources,
};
fn main() {
// Setup printing messages to the console
let console_configuration = ConsoleConfiguration::default();
let console = Console::new("crate_name", &console_configuration);
{
// All output from the tailwind integration will have a `[tailwind]` tag prepended
let console = console.stage("resources");
// provide all resources
let resources = Resources::all(
&console,
// If set to `true` it will generate the `cargo::rerun-if-changed=`
// statements for all resources in local crates (same workspace)
true
);
resources.run().unwrap();
}
}
[!NOTE]
Setting the second argument of
Resources::alltotruemakes theleptos_forge_build_scriptgeneratecargo::rerun-if-changed=statements, which disables the default build script behavior. Depending on your other use cases it might require to adjust your build script behavior.Cargo defaults can be brought back by adding
std::println!("cargo::rerun-if-changed=.")
Tailwind integration is based on cargo-resources
codebase.