CSS Extraction Library for Vite and Preact

(github.com)

3 points | by aziis98 7 hours ago ago

1 comments

  • aziis98 7 hours 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.