Dioxus 0.7-rc.1 Tailwind inclusion doesn't include plugins (DaisyUI)
Problem
In the migration from 0.6 to 0.7-rc.1, I noticed that the current method of including plugins from input.css does not work anymore. Tailwind CSS classes and adaptations are rendered, but DaisyUI-specific styles are not.
https://daisyui.com/docs/install/dioxus/ refers to the inclusion via tailwind.css and not input.css, but no noteable difference is observed. The dx serve Tailwind runner just copies the @plugin directives without expanding them.
Steps To Reproduce
Steps to reproduce the behavior:
- Include DaisyUI as plugin (per https://daisyui.com/docs/install/ ) in
input.css - Run
dx serve --webwithdioxus-cli(v. 0.7-rc.1)
Expected behavior
The manual watcher used in 0.6 was npx @tailwindcss/cli -i ./input.css -o ./assets/tailwind.css --watch, which correctly included the plugin. Either enable the built-in watcher to recognize plugins or allow to use the dedicated Tailwind watcher for non-standard configurations.
Rendering via Tailwind CLI to a separate CSS file (e.g. main.css) does work, but separates the workflow and creates duplicate Tailwind classes when also including the Dioxus file.
If you want to use the tailwind cli embedded in dx you have to have tailwind.css in you project root directory, otherwise you can use npx @tailwindcss/cli.
Hi @omar-mohamed-khallaf, even when using tailwind.css in the project root, @plugin directives are just copied and not properly expanded when running dx serve --web. Is the behavior different on your end?
I use npx not the bundled cli, ~~maybe check if you are using an old version of the cli~~.
After checking the version is hard coded in dioxus so this probably isn't true, the binary doesn't work on my nixos so try running it directly and see if any errors popup.
I figured out how to get daisyui working without using npm / node for dioxus 0.7-rc3 since dx uses the standalone executable for tailwind-cli. The steps are:
- Download https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.mjs and place at the root, at the same place where you put tailwind.css. Note: if you want to define custom themes, you will also need to download https://github.com/saadeghi/daisyui/releases/latest/download/daisyui-theme.mjs and also place it at the root.
- Update the root tailwind.css to be:
@import "tailwindcss";
@source "./src/**/*.{rs,html,css}";
@source not "./tailwindcss";
@source not "./daisyui{,*}.mjs";
@plugin "./daisyui.mjs";
You can then customize daisyui themes the same way you do with the regular .css file, except you have to reference it by .mjs
@import "tailwindcss";
@source "./src/**/*.{rs,html,css}";
@source not "./tailwindcss";
@source not "./daisyui{,*}.mjs";
@plugin "./daisyui.mjs" {
themes: light --default, night --prefersdark;
}
/* for defining custom themes */
@plugin "./daisyui-theme.mjs" {
name: "mycustomtheme";
default: true;
prefersdark: true;
color-scheme: "dark";
--color-base-100: oklch(25.33% 0.016 252.42);
}
Might be interesting if dioxus.toml could have a way to automate this where you can also set the daisyui and tailwind version. Although what is probably better is if daisyui and tailwind could be plugin cargo crates with specified versions where you just include in Cargo.toml and then hook up to dioxus, similar to how tauri does plugins.
@JOSEPHGILBY Thanks for the workaround - works great for me. Just a quick check, I was wondering why the @source not "./tailwindcss"; part is necessary?