Setup

Can use npx tailwind build styles.css -o output.css, but builtin cli doesn't include watch ability need postcss

Setup

yarn add -D tailwindcss postcss-cli autoprefixer
npx tailwind init tailwind.config.js

Add all the files names to content

  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],

Tailwind replaces @tailwind directives with css

index.css

@tailwind base;/* Preflight will be injected here */
/*Put all classes here*/
@tailwind components;
@tailwind utilities;

Preflight is opinionated and makes things like lists, h1, h2, etc unstyled by default

If you're using Next.js you're done, if you using webpack or react-scripts see below

More For React-Scripts

postcss.config.js

Autoprefixer is not required, but automatically tracks caniuse.com and properly prefixes(or unprefixes) css props

package.json

More for Webpack

Tailwind >1.4 does purging if NODE_ENV=production

React Native

Need to use nativewindarrow-up-right

tailwind.config.js

babel.config.js

Now adding className to something will transform it into a styled tailwindcss component

Add the below to an app.d.ts to avoid type errors

Last updated