Manganis CSS Modules Support#3578
Conversation
|
This is still more or less an experiment, but I created this PR to track it, as I believe it could be viable for 0.7 if desired. |
…anis-styles-macro
|
Is it possible to support a syntax for declaring modules that uses a static or a struct as the source item? static MyModule: CSSModule = css_module!("/blah.css");or #[derive(CssModule(file = "/blah.css")]
struct MyModule;I know this might be challenging to achieve but it would be more "idiomatic" rust and likely more discoverable. We'd really want to provide good intellisense and I think providing inline items like this help with rust analyzer. That, and it's usually more transparent to the users of the macro what exactly is being generated. I'll see if I can tinker with getting #1 working but using #2 might be an easier migration for this PR. |
|
@jkelleyrtp I wouldn't know where to begin for 1. but 2. is likely something I can do. |
|
We could try something with extension traits to get #1 working. This would have the benefit that DCE should knock out unused class names, though is slightly worse since you can't really import the module. struct CssModule {}
static MY_MODULE: CssModule = css_module!("");
// generated by the macro
trait LocalExt {
fn id(&self) -> &'static str {
"mymodule"
}
}
impl LocalExt for CssModule {}
fn it_works() {
MY_MODULE.id();
}still brainstorming... If we end up use the struct MyCssModule;
impl MyCssModule {
fn name(&self) -> &'static str {
"Hello, world!"
}
}
fn it_works() {
let p = MyCssModule.name();
} |
* feat: type safe css selectors * feat: css modules support --------- Co-authored-by: Jonathan Kelley <[email protected]>
* feat: type safe css selectors * feat: css modules support --------- Co-authored-by: Jonathan Kelley <[email protected]>
Adds a
css_module!()macro that generates a struct for type-safe, globally unique, classes and ids. This reuses theassetmacro with a newAssetOptionvariant for CSS modules.The macro's docs explain more about how it works & features w/examples.
Breaking
This is breaking as it alters the asset options enum creating a version requirement in the CLI.