How to Set Up Tailwind CSS in Vite React Projects
First of all, we will create a Vite project
Inside the terminal, type the following commands:
npm create vite@latest my-project
cd my-project
Now use the following commands to incorporate Tailwind into your project:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Now we will get a tailwind.config.js file inside our project directory. Inside this file, replace the empty array of content as shown below.
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/*/*.{js,ts,jsx,tsx}",
],
theme:
{ extend: {},
},
plugins: [],
}
Inside our index.css file, we have to add these three lines:
@tailwind base;
@tailwind components;
@tailwind utilities;
Now, we are done with the process. At last, we can run the command
npm run dev
Congrats! Now we can use Tailwind CSS inside our project.
References
Subscribe to my newsletter
Read articles from Sushant Pathak directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sushant Pathak
Sushant Pathak
Hello, This is Sushant, a young developer who is learning and growing each day.