React + Vite + Tailwind project

React + Vite + Tailwind project


This guide will help you init a React project with Vite and use Tailwind.



Prerequisite

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.



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.