How to use this with deno + fresh #1844
Replies: 8 comments
-
Looking at the twind repo, it seem like it doesn't support importing tailwind plugins directly. |
Beta Was this translation helpful? Give feedback.
-
I would recommend against using twind, as it honestly brings more drawbacks than advantages when you want to extend Tailwind with plugins. Especially since twind's plugins are mostly broken or outdated (already had the fun to deal with twind's typography implementation which doesn't allow overrides). I'd recommend the approach to set up native Tailwind with the standalone-cli. Anyway, enough opinions. The fastest way to get daisyUI running is to just import the full stylesheet of daisyUI. Take the following fresh components as an example: import { Head } from "$fresh/runtime.ts"
import { ComponentChildren } from "preact"
interface Props {
children: ComponentChildren
}
const MainLayout = ({ children }: Props) => {
return <>
<Head>
{/* Tailwind Stylesheet */}
<link rel="stylesheet" href="/styles.css" />
{/* DaisyUI */}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css" rel="stylesheet" type="text/css" />
</Head>
<main>
{children}
</main>
</>
}
export { MainLayout } Together with the actual route: import Counter from "../islands/Counter.tsx";
import { MainLayout } from "layouts/MainLayout.tsx";
export default function Home() {
return (
<MainLayout>
<p class="border border-red-500 font-semibold">
Tailwind test with red border.
</p>
<button class="btn btn-outline">This is a daisyUI styled button</button>
<Counter start={3} />
</MainLayout>
);
} |
Beta Was this translation helpful? Give feedback.
-
Hey @VIEWVIEWVIEW I am trying to do just that. Can I ask you for some advice? How do you optimise when using the standalone? I ended up running it as a |
Beta Was this translation helpful? Give feedback.
-
@MarcoSantonastasi I'm not sure what exactly you mean. Please ask again if I understood you wrong. If you want to run commands concurrently, you can do that by concatenating two commands with Ex: {
"tasks": {
"start": "tailwindcss.exe -i input.css -o ./static/styles.css --watch & deno run -A --watch=static/,routes/ dev.ts"
},
} This will run tailwindcss-cli in background and keep building according to your tailwind.config.js When you move to production, you probably want to have a small build step if you're not committing the generated tailwind.config.js /** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./routes/**/*.{tsx,ts}", "./islands/**/*.{tsx,ts}", "./components/**/*.{tsx,ts}"],
theme: {
extend: {},
},
plugins: [],
} Here's a small tree how my files a structured.
download-tailwind.sh (You can replace it with macOS or Linux binary, depending on what you use)
|
Beta Was this translation helpful? Give feedback.
-
Hey @VIEWVIEWVIEW thanks for your reply and apologies for my crappy grammar. site.addEventListener("afterBuild", async () => {
const tailwindBin = await getTwBinFullPath(version, dir);
const process = Deno.run({
cmd: [
tailwindBin,
"-i",
"./_site/css/main.css",
"-o",
"./_site/css/main.css",
],
});
await process.status();
process.close();
}); I was hoping you could shed some light on the best way to take advantage of the tailwind ecosystem in Deno (awesome tech, btw...) considering that realistically you would always be inside a framework (Fresh?) or an SSG (Lume?) |
Beta Was this translation helpful? Give feedback.
-
Take a look here: tailwindlabs/tailwindcss#5710 (comment) |
Beta Was this translation helpful? Give feedback.
-
You can actually run plugins with the tailwind-standalone version. I created a demo repository with lume + tailwind + daisyui + @tailwindcss/typography here: https://github.com/VIEWVIEWVIEW/lume-tailwind-daisyui-typography It's basically the same as I did above: Generate the stylesheet decoupled from the deno process. Using You can still use postcss for other postcss-plugins different from tailwind, if you really insist on doing so. Can you check the repo out and tell me if that's actually a solution for you? |
Beta Was this translation helpful? Give feedback.
-
For anyone on 1.6 Fresh and looking at this thread. Fresh now supports real tailwind ✅ : https://fresh.deno.dev/docs/examples/migrating-to-tailwind Adding daisyUI is as easy as this: import { type Config } from "tailwindcss";
import daisyui from "npm:daisyui@latest";
export default {
content: [
"{routes,islands,components}/**/*.{ts,tsx}",
],
plugins: [
daisyui,
],
} satisfies Config; |
Beta Was this translation helpful? Give feedback.
-
Hi, how can I use this UI framework with Deno + Fresh + Twind? I tried importing it from https://esm.sh/daisyui and importing it in twind configuration, but it does not work, styles just do not apply.
Beta Was this translation helpful? Give feedback.
All reactions