Crates.io | css-loader-macros |
lib.rs | css-loader-macros |
version | 0.0.1 |
source | src |
created_at | 2022-08-18 10:15:26.67842 |
updated_at | 2022-08-18 10:15:26.67842 |
description | A simple macro to include style files in Rust using CSS Modules-like scoping |
homepage | |
repository | |
max_upload_size | |
id | 648077 |
size | 8,526 |
A simple macro to include style files in Rust using CSS Modules-like scoping.
use yew::prelude::*;
import_style!("src/styles.scss");
#[function_component(App)]
fn app() -> Html {
html! {
<h1 class={styles.header}>{ "Hello World" }</h1>
}
}
fn main() {
println!("Hello, world!");
yew::start_app::<App>();
}
$textcolor: yellow;
$fontsize: 18px;
.header {
color: $textcolor;
font-size: $fontsize;
}
Styles are imported relative to CARGO_MANIFEST_DIR
, basically the directory that contains the Cargo.toml
file. It would be nice to do relative path imports like in Javascript, however, due to a little limitation in the Rust compiler, this can't be done right now.
Secondly, the same limitation prevents us from having a way to "link" the style file to the Rust source file, hence modifying the style files won't trigger a rebuild/reload.
These both issues be addressed after this API is stabilized in the Rust compiler.
.css
files are imported directly and .scss
are compiled with rsass and loaded automatically.