Crates.io | css_mod |
lib.rs | css_mod |
version | 0.1.5 |
source | src |
created_at | 2022-03-31 08:48:20.943481 |
updated_at | 2022-05-18 09:19:23.975038 |
description | CSS Modules implementation for Rust web applications |
homepage | https://github.com/art-in/css_mod |
repository | https://github.com/art-in/css_mod |
max_upload_size | |
id | 559538 |
size | 35,206 |
CSS Modules implementation for Rust web applications
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default.
This is currently incomplete implementation of CSS Modules spec, as it only supports the vital features.
@counter-style
:local()
/ :global()
composes
url()
/ @import
Add this crate as a regular and build dependency:
# Cargo.toml
[dependencies]
css_mod = "0.1.0"
[build-dependencies]
css_mod = "0.1.0"
Create build script and call compiler:
// build.rs
fn main() {
css_mod::Compiler::new()
.add_modules("src/**/*.css").unwrap()
.compile("assets/app.css").unwrap();
}
Call init somewhere early in program execution:
// src/main.rs
fn main() {
css_mod::init!();
}
Finally get name mapping for CSS module:
// src/my-component.rs
let css = css_mod::get!("my-component.css");
let global_class_name = css["local-class-name"]; // my-component__local-class-name__0
Look in the examples directory.