This is the repo for swyx's blog - Blog content is created in github issues, then posted on swyx.io as blog pages! Comment/watch to follow along my blog within GitHub
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 /src
darkMode: ['class', '[data-theme="dark"]'], // hooks into docusaurus' dark mode settigns
theme: {
extend: {},
},
plugins: [],
}
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 <div className="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 off