Quickly Set Up Tailwind CSS with Vite for React Apps in Just One Minute

Posted by


In this tutorial, we will learn how to set up Tailwind CSS with Vite in under 60 seconds. Tailwind CSS is a popular utility-first CSS framework, while Vite is a modern build tool that helps with fast and efficient development. By combining Tailwind CSS with Vite, we can create a seamless development experience for building responsive and intuitive web applications.

To get started, make sure you have Node.js installed on your machine. If not, you can download and install it from the official Node.js website. Once Node.js is installed, open your terminal and create a new React project by running the following command:

npx create-react-app my-tailwind-project

Next, navigate into your project directory by running the following command:

cd my-tailwind-project

Now, let’s install Tailwind CSS and its dependencies by running the following command:

npm install -D tailwindcss@latest postcss@latest autoprefixer@latest

After installing Tailwind CSS, you need to generate a Tailwind configuration file by running the following command:

npx tailwindcss init

Next, create a tailwind.css file in your src directory and add the following Tailwind CSS imports:

@tailwind base;
@tailwind components;
@tailwind utilities;

Now, let’s set up Vite to work with Tailwind CSS. Create a vite.config.js file in the root of your project and add the following configuration:

import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import WindiCSS from 'vite-plugin-windicss';

export default defineConfig({
  plugins: [reactRefresh(), WindiCSS()],
});

Finally, you can import the tailwind.css file in your index.css file to apply Tailwind CSS styles to your React components:

@import './src/tailwind.css';

That’s it! You have successfully set up Tailwind CSS with Vite in your React project. Now you can start building amazing web applications with responsive and intuitive designs using Tailwind CSS. Happy coding!

0 0 votes
Article Rating

Leave a Reply

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@shivammishraji
2 hours ago

Bro sara setup ho vya hae ract with tailwind but tailwind property apply nhi ho rhi hae UI me

@dileepd2931
2 hours ago

What is the error showing in the index.css file

@AtikshaSharma-k5d
2 hours ago

Not working i am doing same steps but tailwind is not working

@ajtechnical3466
2 hours ago

Thanku bro it's helpful 😌

@factworld1030
2 hours ago

Nhi ho rha💔

5
0
Would love your thoughts, please comment.x
()
x