Tailwind CSS
A utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.
Go to Docs β
#
Configuration filesTailwind plugin produces the two necessary config files: tailwind.config.js
and craco.config.js
See Tailwind configuration docs β
#
Include Tailwind in your CSSTailwind is imported directly in App.tsx
import "tailwindcss/tailwind.css";
You can also include tailwind in your custom css β
#
Purging unused stylestailwind.config.js
is configured to purge unused styles in pages and components.
module.exports = { purge: ["./src/**/*.tsx"]}
See guide on optimizing for production on Tailwind docs β
#
Configuring PostCSSSince Create React App doesn't let you override the PostCSS configuration natively. We need to create a craco.config.js
file to set up Tailwind with React properly.
module.exports = { style: { postcss: { plugins: [ require('tailwindcss'), require('autoprefixer'), ], }, }, }
#
Adding Tailwind CSS to your project later- npm
- yarn
npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
npm install @craco/craco
yarn add tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
yarn add @craco/craco
{ // ... "scripts": {- "start": "react-scripts start",- "build": "react-scripts build",- "test": "react-scripts test",+ "start": "craco start",+ "build": "craco build",+ "test": "craco test", },}
Refer to official documentation for detailed installation. β