Create a React + TypeScript + Tailwind project with Vite
To quickly bootstrap a new React project with TypeScript using Vite, you can use the following npm command:
shellnpm create vite@latest react-app -- --template react-ts
Or if you prefer yarn:
shellyarn create vite react-app --template react-ts
This will create a new directory called react-app with a basic project structure already set up for a React + TypeScript application.
Once the project is created, navigate into the directory:
shellcd react-app
Then install the dependencies:
shellnpm install
Finally, start up the dev server:
shellnpm run dev
Install and configure Tailwind
To install Tailwind CSS and its peer dependencies, run:
shellnpm install tailwindcss @tailwindcss/vite --save-dev
Next, open vite.config.ts and add:
vite.config.tsimport { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import tailwindcss from '@tailwindcss/vite' // https://vite.dev/config/ export default defineConfig({ plugins: [react(), tailwindcss()], })
Open the index.css file in your project's src directory and replace its content with the following:
index.css@import "tailwindcss";
To import Tailwind in the project, open the main.tsx file and add the following line at the top of the file (if it's not already there)
htmlimport './index.css';
Removing Unnecessary CSS Imports
If you have any existing CSS imports in your .tsx files, you can now remove them. Tailwind CSS will handle all the styling for you, so you don't need to import individual CSS files anymore.