DEV Community

Cover image for React + Vite + Tailwind project
Khang Nguyen
Khang Nguyen

Posted on

React + Vite + Tailwind project

If you want to create a React project without using framework like NextJS or Remix, this article is for you. In this guide I will help you init a React project with Vite and use TailwindCss.

Prerequisite

  • NodeJS version >= 18

Use this command to check your NodeJS version

node -v
Enter fullscreen mode Exit fullscreen mode

Create react project with vite

Open your terminal and run the command

npm create vite@latest
Enter fullscreen mode Exit fullscreen mode

It would ask you some question:

  • Project name: Your project name, example: pokemon
  • Select a framework: Choose React
  • Select a variant: Pick TypeScript

Then your project is created, open the project by VSCode or your other IDE and install dependencies by this command:

npm install
Enter fullscreen mode Exit fullscreen mode

To run project in dev mode, run

npm run dev
Enter fullscreen mode Exit fullscreen mode

The project would be run at http://localhost:5174

Integrate with Tailwind

Install Tailwind by command

npm install -D tailwindcss postcss autoprefixer
Enter fullscreen mode Exit fullscreen mode

Then init Tailwind config file

npx tailwindcss init -p
Enter fullscreen mode Exit fullscreen mode

Update file tailwind.config.js following this code

content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
Enter fullscreen mode Exit fullscreen mode

Open index.css file import all tailwind css styles

@tailwind base;
@tailwind components;
@tailwind utilities;
Enter fullscreen mode Exit fullscreen mode

Now let's test your Tailwind with this code in any .tsx file

<h1 className="text-3xl font-bold underline">
      Hello world!
</h1>
Enter fullscreen mode Exit fullscreen mode

If the styles are applied, you successfully initialized a React project with Tailwind and Vite.

Top comments (0)