Load the stylesheet as a file
<AuroraStyles /> puts the stylesheet on the page when the app starts, so
the page can show unstyled content for a moment. A <link> in the <head>
loads the stylesheet before the first paint. Aurora ships the CSS inside the
crate; aurora_leptos::write_css(dir) writes it to dir/aurora.css.
With Trunk
Section titled “With Trunk”Trunk checks its assets before it builds the crate, so a build.rs is too
late. Write the file in a pre_build hook. Cargo cannot run a binary of a
dependency, so the hook runs a small helper crate of your own.
-
Make the helper crate
tools/aurora-css/Cargo.toml:[package]name = "aurora-css"version = "0.0.0"edition = "2021"publish = false[dependencies]colliery-io-aurora = { version = "0.7", default-features = false }With
default-features = falsethe helper does not build Leptos. -
Write
tools/aurora-css/src/main.rs:fn main() {let dir = std::env::args().nth(1).unwrap_or_else(|| "style".into());let path = aurora_leptos::write_css(std::path::Path::new(&dir)).expect("write aurora.css");eprintln!("aurora-css: wrote {}", path.display());} -
Add
"tools/aurora-css"tomembersin the[workspace]of your rootCargo.toml. The helper then uses the sameCargo.lock, and the same Aurora version, as the app. -
Add the hook to
Trunk.toml:[[hooks]]stage = "pre_build"command = "cargo"command_arguments = ["run", "-q", "-p", "aurora-css","--target-dir", "target/_aurora_css","--", "style",]The separate target folder stops the hook from rebuilding the app.
-
In
index.html, link the file afterTHEME_INIT_SCRIPT:<script>/* THEME_INIT_SCRIPT */</script><link data-trunk rel="css" href="style/aurora.css" /> -
Remove
<AuroraStyles />from the app. -
Add
style/aurora.cssto.gitignore. The hook makes it.
If your product is not a Cargo workspace, give the helper crate its own
[workspace] table, and run it with --manifest-path tools/aurora-css/Cargo.toml.
Pin the same Aurora version as the app.
Or install the binary
Section titled “Or install the binary”The crate has a binary, aurora-css, behind the bin feature. Install it on
each machine and in CI, at the version of the app:
cargo install colliery-io-aurora --locked --version 0.7.0 --no-default-features --features binThen the hook is:
[[hooks]]stage = "pre_build"command = "aurora-css"command_arguments = ["style"]aurora-css <dir> writes <dir>/aurora.css. With --hyper it also writes
<dir>/hyper.css.
With cargo-leptos
Section titled “With cargo-leptos”cargo-leptos builds the crate before it processes the styles, so a
build.rs works.
- Add Aurora to
[build-dependencies], withdefault-features = false. - In
build.rs, callaurora_leptos::write_css(...)with a folder. - Point
style-filein[package.metadata.leptos]at theaurora.cssthat it writes.
The stylesheet loads IBM Plex from Google Fonts. To ship with no network, host the fonts yourself.