This is a very basic Tailwind v4 setup for Docusaurus v3.
Install Tailwind and Postcss:
npm i --save-dev tailwindcss postcss @tailwindcss/postcss
Create docosaurus plugin in src/plugins/tailwind-config.js:
module.exports = function tailwindPlugin(context, options) {
return {
name: "tailwind-plugin",
configurePostCss(postcssOptions) {
postcssOptions.plugins = [require("@tailwindcss/postcss")];
return postcssOptions;
},
};
};
Add this plugin to docosaurus config object in docusaurus.config.ts:
const config: Config = {
//...
plugins: ["./src/plugins/tailwind-config.js"],
//...
};
Add tailwind setup somewhere in src/css/custom.css file:
@import "tailwindcss";
@custom-variant dark (&:is([data-theme="dark"] *));
And voila! From now on, Tailwind classes should be picked up by Docosaurus and the dark theme will also sync up correctly.
Top comments (5)
It works, but some classes are overridden by Infima. How can I fix this?
For example, I have an h1 tag with Infima’s default styles. I apply Tailwind classes, but they don’t take priority and get overridden by Infima.
Do you have any solution? I add default important, it work but i think it not good, it make default any class has !important.
thanks ~~
My docusaurus can use tailwindcss
Thanks!! That's all I need.
Awesome, that helped me upgrade to v4, thanks ❤️
Thanks, Michał! You're the best!