I'm working on a project using Rspack, React, Tailwind CSS, and TypeScript. I'm having trouble integrating DaisyUI.
According to the official DaisyUI v5 documentation for Vite, you need to import DaisyUI in tailwind.config.ts
and postcss.config.js
, but I'm not sure how to adapt this for Rspack.
postcss.config.mjs
export default { plugins: {"@tailwindcss/postcss": {},},};
rsbuild.config.ts
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
export default defineConfig({
plugins: [
pluginReact()
]});
rspack.config.ts
export default {
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
],
},
],
},
};
In my app.css
file, I tried importing Tailwind and DaisyUI:
@import "tailwindcss";
@import "daisyui"; /* When I add this line, it doesn't work */
However, when I uncomment the DaisyUI line, it doesn't work.
Pre-transform error: Can't resolve 'daisyui' in ...
How can I configure Rspack properly so that DaisyUI works with Tailwind CSS? Do I need to add any specific configurations in rspack.config.ts
or postcss.config.mjs
?
I would appreciate any help or examples of a working setup.
With the release of DaisyUI v5, the documentation has been updated and now includes the necessary installation steps for TailwindCSS v4.
How to install daisyUI as a Tailwind CSS plugin?
You need Node.js and Tailwind CSS installed.
Install daisyUI as a Node package:
npm i -D daisyui@latest
Add daisyUI to app.css:
@import "tailwindcss"; @plugin "daisyui";
Starting from v4, the @plugin
CSS-first directive is available for installing TailwindCSS plugins.
app.css
@import "tailwindcss";
@plugin "daisyui"; /* not @import */
The Pre-transform error: Can't resolve 'daisyui' in ...
error message is generated by the @import
, which cannot find the file or module to import for DaisyUI. And it is correct, as this is a special TailwindCSS plugin that can only be interpreted by TailwindCSS.
You are using Rspack with React.
The installer for TailwindCSS v4 recommends the PostCSS plugin for Rspack.
If you are using TailwindCSS with PostCSS, you will also need to install DaisyUI with PostCSS.
You might see slightly different installation steps when using PostCSS compared to Vite. I'll explain in detail:
Dependencies
npm install tailwindcss @tailwindcss/postcss postcss postcss-loader daisyui@beta
rspack.config.ts
export default defineConfig({
// ...
module: {
rules: [
{
test: /\.css$/,
use: ["postcss-loader"],
type: "css",
},
// ...
],
},
}
postcss.config.mjs
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
app.css
@import "tailwindcss";
@plugin "daisyui"; /* not @import */
Important! You only need to import TailwindCSS. All other plugins can be added using the @plugin
directive!