"Instant On-demand Atomic CSS Engine" - UnoCSS
- 💉 Automatic injection of generated CSS into HTML files
- 🪄 On-demand CSS generation using UnoCSS core
- 🚀 Seamless integration with Bun's build system
- 📦 Support for HTML file processing with UnoCSS rules
- 🎨 Highly configurable
- 🔄 Real-time CSS generation during development
- ⚡ Zero-config setup with automatic UnoCSS config detection
bun install -d bun-plugin-unocss
You may now use the plugin now via Bun.build
:
// build.ts
import type { UserConfig } from 'unocss'
import { plugin as unocss } from 'bun-plugin-unocss'
// import unocss from 'bun-plugin-unocss'
const config: UserConfig = {
// Your UnoCSS config
}
Bun.build({
entrypoints: ['./src/index.html'],
outdir: './dist',
plugins: [
unocss(config), // by default, it will look for the Uno config file in the project root
],
})
Additionally, it can also be used in conjunction with HTML imports, via Bun.serve()
:
// server.ts
import home from './home.html'
const server = Bun.serve({
static: {
// Bundle & route home.html to "/home"
'/': home,
},
async fetch(req) {
console.log('any other request', req.url)
// Return 404 for unmatched routes
return new Response('Not Found', { status: 404 })
},
})
console.log(`Listening on ${server.url}`)
<!-- home.html -->
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<div id="root">Root Element</div>
<div class="mt-24 text-red-500">Test</div>
</body>
</html>
For this to work, though, you have to ensure that the plugin is defined in your bunfig.toml
:
[serve.static]
plugins = [ "bun-plugin-unocss" ]
bun test
Please see our releases page for more information on what has changed recently.
Please review the Contributing Guide for details.
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
You will always be free to use any of the Stacks OSS software. We would also love to see which parts of the world Stacks ends up in. Receiving postcards makes us happy—and we will publish them on our website.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
Many thanks to the following core technologies & people who have contributed to this package:
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙