https://github.com/stacksjs/bun-plugin-unocss
Bun plugin for UnoCSS support.
https://github.com/stacksjs/bun-plugin-unocss
bun bun-plugin unocss
Last synced: about 1 year ago
JSON representation
Bun plugin for UnoCSS support.
- Host: GitHub
- URL: https://github.com/stacksjs/bun-plugin-unocss
- Owner: stacksjs
- License: mit
- Created: 2025-02-02T21:21:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-11T21:13:24.000Z (about 1 year ago)
- Last Synced: 2025-04-11T22:26:52.627Z (about 1 year ago)
- Topics: bun, bun-plugin, unocss
- Language: TypeScript
- Homepage:
- Size: 391 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README

[![npm version][npm-version-src]][npm-version-href]
[![GitHub Actions][github-actions-src]][github-actions-href]
[](http://commitizen.github.io/cz-cli/)
[![npm downloads][npm-downloads-src]][npm-downloads-href]
# bun-plugin-unocss
> "Instant On-demand Atomic CSS Engine" - UnoCSS
## Features
- π 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
## Usage
```bash
bun install -d bun-plugin-unocss
```
### Bundler
You may now use the plugin now via `Bun.build`:
```ts
// 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, // by default, it will look for the Uno config file in the project root
],
})
```
### Server
Additionally, it can also be used in conjunction with HTML imports, via `Bun.serve()`:
```ts
// 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}`)
```
```html
Home
Root Element
Test
```
#### Configuration
For this to work, though, you have to ensure that the plugin is defined in your `bunfig.toml`:
```toml
[serve.static]
plugins = [ "bun-plugin-unocss" ]
```
## Testing
```bash
bun test
```
## Changelog
Please see our [releases](https://github.com/stacksjs/bun-plugin-unocss/releases) page for more information on what has changed recently.
## Contributing
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
## Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
For casual chit-chat with others using this package:
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
## Postcardware
βSoftware that is free, but hopes for a postcard.β We love receiving postcards from around the world showing where `bun-plugin-unocss` is being used! We showcase them on our website too.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States π
## Sponsors
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.
- [JetBrains](https://www.jetbrains.com/)
- [The Solana Foundation](https://solana.com/)
## Credits
Many thanks to the following core technologies & people who have contributed to this package:
- [UnoCSS](https://unocss.dev)
- [Anthony Fu](https://github.com/antfu)
- [Chris Breuer](https://github.com/chrisbbreuer)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/bun-plugin-unocss/tree/main/LICENSE.md) for more information.
Made with π
[npm-version-src]:
[npm-version-href]:
[npm-downloads-src]:
[npm-downloads-href]:
[github-actions-src]:
[github-actions-href]: