UnoCSS is a utility-first CSS framework, much like TailwindCSS, but much more pluggable.
It’s so modular that you can UnoCSS’s @unocss/preset-icons preset alone to handle icons only, and I was impressed by it, I mean, look at this, using SVG icons in pure CSS, only bundle what I use, how cool is that?
It’s incredibly cool, but I’m not yet ready to fully ditch TailwindCSS to migrate to UnoCSS, I’ll start with the icons.
Another good thing about this is that I no longer need to inline SVG icons in my React component, currently, I’m just manually copying whatever SVG icons I want from https://icones.js.org as JSX into the app, it’s somewhat a bad practice:
Adding UnoCSS to my Next.js app
Install the dependencies:
Configure uno.config.ts:
Then create an npm script to generate CSS using UnoCSS’s CLI:
I’m using Next.js, so I need to import the generated CSS in my src/pages/_app.tsx
To automate the uno-generate script, I created a webpack plugin and added it to next.config.js:
This plugin will make webpack run pnpm uno-generate before compiling your app, in development, it also runs in watch mode.
That’s about it, I think I’ll gradually move to UnoCSS, and replace my TailwindCSS @apply rules with UnoCSS shortcuts when I get some time.