Playing with unocss
Slimmer than tailwind, but still cool
- tags
- unocss
- tailwind
Contents
I stumbled upon Anthony Fu's Reimagine Atomic CSS post the other day, and his fine work on unocss.
The basic idea simply scan the HTML/whatever files for all of the classes that are used, and then generate the css based on that. This results in a much faster build time, and also smaller CSS files. And you can use the same classes that you are used to with Tailwind.
|
|
|
|
That's only 3K!
There's also a couple of other cool features. One that I think is very useful is the web fonts preset, which does some boilerplate lifting that's a bit awkward in Tailwind.
|
|
Lets get started on how to use it without any fancy frameworks.
live-server
First we can start up a live server with
|
|
Basic page with unocss runtime
site/basic.html
|
|
Generating css using watch
That's nice any easy, but lets setup our own config file, and we can add a couple of other plugins to make things easier.
uno.config.ts
:
|
|
Then create package.json
as
|
|
And set it up and run
|
|
Now we can replace
|
|
with:
|
|
That will give us:
site/inline.html
:
|
|
References
Previously
Next