How to install Tailwind CSS and daisyUI in a Elysia project
Install Bun, according to theofficial Bun docs
Create a new Elysia project
bun create elysia myapp
cd myapp
Install@elysiajs/static
bun install @elysiajs/static
bun install tailwindcss@latest @tailwindcss/cli@latest daisyui@latest
Add Tailwind CSS and daisyUI to your CSS file
@import "tailwindcss" source(none);
@source "../public";
@plugin "daisyui";
Create a server file atsrc/index.ts
with functions to build CSS and watch for changes
import { Elysia } from "elysia";
import { staticPlugin } from '@elysiajs/static'
import { exec } from 'child_process'
import { watch } from 'fs'
const buildCSS = () =>
new Promise(resolve =>
exec('tailwindcss -i ./src/app.css -o ./public/output.css',
(_error, _stdout, stderr) => {
console.log(stderr);
resolve(null);
})
);
await buildCSS();
const watcher = watch('./public', { recursive: true },
async () => {
await buildCSS();
}
);
process.on('SIGINT', () => {
watcher.close();
process.exit(0);
});
const app = new Elysia()
.use(
staticPlugin({
assets: "public",
prefix: "",
}),
)
.listen(3000, ({ hostname, port }) => {
console.log(`Server started http://${hostname}:${port}`);
});
Create apublic/index.html
file with the following content
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/output.css">
</head>
<body>
<button class="btn btn-primary">Hello daisyUI</button>
</body>
</html>
Run the server
bun run dev
Now you can use daisyUI class names!