Settings

Theme

CSS Extraction Library for Vite and Preact

github.com

3 points by aziis98 3 months ago · 1 comment

Reader

aziis98OP 3 months ago

This is a small TailwindCSS alternative based on a css template literal. I was inspired by styled-components and EmotionCSS, which however do not work well with ViteJS and specifically Preact.

I wanted something more optimized than other CSS-in-JS alternatives that generate CSS at runtime, so I created a ViteJS plugin. It extracts all style snippets, replaces them with classes like css-a1b2c3, and injects all the corresponding styles into a CSS file in place of an @extracted-css directive.

This provides a better experience than Tailwind, as you can use all CSS language features without learning new conventions while maintaining a per-component styling approach. This turns out to be more inspectable in the browser's dev-tools, as snippets are extracted as-is and are not fragmented across thousands of small classes.

There is also a preact options hook that adds a custom classList attribute, which maps to clsx for easy class composition (similarly to VueJS, Svelte, etc.).

P.S. I know other frameworks exist, but I have really been enjoying using Preact for frontend development recently.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection