How to Create a New React Project using Vite with TailwindCSS
In this article you will learn how to initialize a React project using the Vite bundler with TailwindCSS for styling.

Search for a command to run...
In this article you will learn how to initialize a React project using the Vite bundler with TailwindCSS for styling.

No comments yet. Be the first to comment.
Before we start This guide assumes: You are using a recent version of .NET (.NET 6+) and that you are using JWT authentication with Auth0. You have already followed an Auth0 guide to setup API authentication for ASP.NET but cannot fix the error men...
This post explains the simple process of installing a Windows game manually using Lutris with step-by-step instructions.

This is a simple guide to installing Linux targeted specifically at beginners. This post covers most of the basic principles of Linux and they work.

This is a guide on how to use the Hugo static site generator with Github's free hosting solution, Github Pages.

Before learning how to initialize the project, we must first learn what exactly Vite, TailwindCSS, and npm/yarn are. Here are some short descriptions:
Here is what we are going to do:
Notes:
create-react-app in the past, you might have noticed the index.html file is outside the public folder. This is how Vite chooses to organize it's file structure and is normal. To learn more: https://vitejs.dev/guide/#index-html-and-project-rootWith npm: npm create vite@latest
With yarn: yarn create vite
Note: You MUST complete the previous step for this to work
yarn
yarn add -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
npm install
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Line-by-line explanation of the above commands:
tailwind.config.js file in the root directory of your project.Note: You should see a new file called tailwind.config.js, if you do not, run npm tailwindcss init -p again.
Open the file and delete everything. Next, paste the following code in the file and save:
module.exports = {
content: ["./index.html", "./src/**/*.{vue,js,ts,jsx,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
Next, open the index.css file in the src directory and delete everything. Then, paste the following:
@tailwind base;
@tailwind components;
@tailwind utilities;
Note: If you started the development server earlier, before you finished configuring Tailwind, Tailwind might not work. Shutdown the server and try again.
Open up the App.jsx file and change on the element's class name with a Tailwind utility name.
For example you can change one of the <p> element's class name:

Now, run yarn run dev (you can use npm instead as well). This will start the Vite development server on http://localhost:3000 or another address if port 3000 is in use.
Navigate to your development server's URL (as shown when you start the server). It should look something like this:

Today you learned: