Compile-time CSS generation
See original GitHub issueIt would be fantastic to generate CSS at compile-time instead of runtime, mainly because it would reduce the output JS size to near zero, making #72 obsolete.
Example:
val abc = style(display.block)
// Macro turns ↑ into something like ↓
val abc = StyleA(…, PreGeneratedCss("display:block"))
It would have to handle autoprefixing too.
How/could it determine whether variables are static/dynamic to handle marginLeft(zzz.px * 2)
?
Even if it just takes care of the easy, static cases, I wonder how large the JS size savings could be…
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Build Time CSS-in-JS: Explained - DEV Community
Have you heard about Build Time CSS-in-JS libraries? ... generating, and rendering CSS through JS, which impacts directly and positively ...
Read more >Compiled: A CSS-in-JS library without the runtime cost
The fantastic developer experience of writing CSS inside JavaScipt files comes at the cost of generating CSS at runtime.
Read more >style9: build-time CSS-in-JS
To generate a class name, we can now call the function returned by style9.create . It accepts as arguments the keys of the...
Read more >Compiled | Compile time CSS-in-JS for React
compile time CSS -in-JS library for React. Styled CSS prop. Class names. View transformed code. import { styled } from '@compiled/react'; export const...
Read more >Build-time CSS generator
Build -time CSS generator. 상태. IDEAs. •. generate functional-css style stylesheet at build(compile) time.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh very cool, thanks! How do you handle supporting both dev and prod modes? (Specifically, controlling whether the macros generate verbose or minimised CSS?)
Also, a few weeks ago I did a prototype for scalacss v2 and it worked 🎉 I’m envisioning a future where you just paste normal CSS and it calls out to the JS ecosystem at compile-time to do things like validation, minification, auto-prefixing, etc. The idea of a Scala-based DSL for CSS has turned out to be a failure in my opinion.
I’m envisioning something like this:
It would still need some custom stuff to be able to support things like
addClassNames
but should be quite a small surface area.What do you think?
We use scalacss with compile-time / backend CSS rendering quite extensively in udash-css, while reusing most of the DSL. The output JS is just the classnames (safe to use though!). You can check https://guide.udash.io/frontend/templates or dive into the code https://github.com/UdashFramework/udash-core/tree/master/css, https://github.com/UdashFramework/udash-core/blob/master/macros/src/main/scala/io/udash/css/macros/StyleMacros.scala