You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use Docusaurus at work, and while it shipped v2 this year it still has (as of v2.3) not shipped with any Tailwind support at all. Googled and found this post which was almost everything I needed, but required some stuff in the comments for it to work.
Here are the requirements I have, that differed from that blogpost:
do not activate Tailwind's CSS Reset, Preflight, because it wipes out the rest of Docusuarus' styles
support Docusaurus' dark mode
just writing down my version that affirmatively worked for me.
Step 1 - install stuff
# in the docusarus directory
yarn add tailwindcss postcss autoprefixer
touch tailwind.config.js # intentionally empty; we'll fill in our own in a bit
Step 2 - Setup tailwind config and css files
// tailwind.config.js/** @type {import('tailwindcss').Config} */module.exports={corePlugins: {preflight: false,// disable Tailwind's reset},content: ["./src/**/*.{js,jsx,ts,tsx}","../docs/**/*.mdx"],// my markdown stuff is in ../docs, not /srcdarkMode: ['class','[data-theme="dark"]'],// hooks into docusaurus' dark mode settignstheme: {extend: {},},plugins: [],}
// ...plugins: [// ....asyncfunctionmyPlugin(context,options){return{name: "docusaurus-tailwindcss",configurePostCss(postcssOptions){// Appends TailwindCSS and AutoPrefixer.postcssOptions.plugins.push(require("tailwindcss"));postcssOptions.plugins.push(require("autoprefixer"));returnpostcssOptions;},};},],
and you are done.
to test, convert /docs/whatever.md to /docs/whatever.mdx and insert a React element or component (did you know you can define React components inline in MDX? its weird af, but it works...)
export function Section() {
return <divclassName="bg-red-500 dark:bg-yellow-500">this is tailwind!</div>
}
# Welcome to Docs
this works in light and dark mode
<Section />
whoooo it works
category: tutorial
slug: tailwind-docusaurus-2022
We use Docusaurus at work, and while it shipped v2 this year it still has (as of v2.3) not shipped with any Tailwind support at all. Googled and found this post which was almost everything I needed, but required some stuff in the comments for it to work.
Here are the requirements I have, that differed from that blogpost:
just writing down my version that affirmatively worked for me.
Step 1 - install stuff
Step 2 - Setup tailwind config and css files
and also the
@tailwind
includes:Step 3 - Custom docusaurus plugin
this part is exactly as per the blogpost:
and you are done.
to test, convert
/docs/whatever.md
to/docs/whatever.mdx
and insert a React element or component (did you know you can define React components inline in MDX? its weird af, but it works...)Caveats
Because preflight is off, some assumptions break:
border-solid
for borders because preflight is offThe text was updated successfully, but these errors were encountered: