Kirby Vite UnoCSS Kit
A powerful and performant integration of Vite, UnoCSS and Kirby. This project seeks to provide a best practice that combines these three solutions while focusing on the development experience.
Key Features
-
β‘οΈ Vite β HMR and all the bells and whistles -
π Module system inspired by Nuxt.js -
π‘ On-demand template loading -
πͺ Page reload on snippet/template changes -
π¨ UnoCSS β on-demand atomic CSS engine similar to Tailwind CSS -
π SEO-friendly defaults -
π¦Ύ TypeScript, of course
Why UnoCSS
tl;dr: Write your CSS like you prefer to and pull in only the utilities you need on top.
Let me cite Anthony Fu:
UnoCSS is an atomic-CSS engine instead of a framework. Everything is designed with flexibility and performance in mind. In UnoCSS, there are no core utilities; all functionalities are provided via presets.
By default, UnoCSS applies the default preset. Which provides a common superset of the popular utilities-first framework, including Tailwind CSS, Windi CSS, Bootstrap, Tachyons, etc.
For example, for this kit only the following utilities are generated:
.box{padding:1rem;margin-left:auto;margin-right:auto;--un-bg-opacity:1;background-color:rgba(244,244,245,var(--un-bg-opacity));border-radius:0.375rem;--un-shadow-color:0,0,0;--un-shadow:0 1px 2px 0 rgba(var(--un-shadow-color), 0.05);-webkit-box-shadow:var(--un-ring-offset-shadow, 0 0 #0000), var(--un-ring-shadow, 0 0 #0000), var(--un-shadow);box-shadow:var(--un-ring-offset-shadow, 0 0 #0000), var(--un-ring-shadow, 0 0 #0000), var(--un-shadow);max-width:7xl;}
.px-4{padding-left:1rem;padding-right:1rem;}
.py-4{padding-top:1rem;padding-bottom:1rem;}
.mx-auto{margin-left:auto;margin-right:auto;}
.mb-4{margin-bottom:1rem;}
.max-w-screen-md{max-width:768px;}
You may also want to give this blog post a read Reimagine Atomic CSS for the story behind.
Installation
- Duplicate the
.env.example
as.env
and optionally adapt its values depending on your environment:
cp .env.example .env
- Install the required dependencies:
npm install
composer install
Configuration
To add custom rules or shortcuts, edit the unocss.config.ts
.
For example, this project already defines a box
class via a shortcut:
shortcuts: {
'box': 'max-w-7xl mx-auto bg-gray-100 rounded-md shadow-sm p-4'
}
Usage
Development
- Build assets and watch for changes accordingly:
npm run dev
- Run the PHP built-in web server or use a development web server of your choice (like Laravel Valet).
composer start
Production
Build the frontend assets (CSS & JS files):
npm run build
If you have caching enabled, make sure to wipe the cache after each build:
rm -rf storage/cache/<your-website>
Deployment
- Deploy whole repository on your server.
- Duplicate
.env.example
as.env
. - Install dependencies:
npm install
composer install
- Build frontend assets:
npm run build
- Point your web server to the
public
folder. - For Apache web servers: Some hosting environments require to uncomment
RewriteBase /
in.htaccess
to make site links work.