[][src]Crate css_modules

The CSS Modules project defines CSS Modules as:

A CSS Module is a CSS file in which all class names and animation names are scoped locally by default.

This implementation is however currently immature and has not (as far as I'm aware) been used in a real world situation. Currently only animation and class names are locally scoped and the following work is in progress:

  • Inlining url() and @import statements
  • Creating or integrating with a asset compilation tool tool (Rollup, Webpack, etc)


Add this crate as a build dependency and as a regular dependency:

css-modules = "0.5"

css-modules = "0.5"

Create a build script (build.rs) in the root of your project:

This example is not tested
use css_modules::CssModules;

fn main() {
    let mut css_modules = CssModules::default();

    // Include all CSS files in the src dir:

    // Compile all modules and export CSS into one file:

And then finally, you can include CSS modules:

This example is not tested
use css_modules::include_css_module;

let css = include_css_module!("example.css"); // relative path to your CSS
let myClass = css["original-class-name"]; // aliased class name

For more detailed examples, look in the examples/ directory.





Returned from the include_css_module!("...") macro.


Used internally in the include_css_module!("...") macro to create modules.


A tool for compiling CSS Modules.