HomeAbout Me

πŸš€ Setting Up a React Project with Vite

By Daniel Nguyen
Published in React JS
September 25, 2024
1 min read
πŸš€ Setting Up a React Project with Vite

🧰 Prerequisites

Before we begin, make sure you have the following installed:

  • Node.js (version 14.18+, 16+ recommended)
  • npm or Yarn
  • A code editor like VS Code

βš™οΈ Step 1: Create a Vite Project

Open your terminal and run the following command to scaffold a new Vite + React project:

npm create vite@latest my-react-app -- --template react

Or with Yarn:

yarn create vite my-react-app --template react

Replace my-react-app with your desired project name.


πŸ“ Step 2: Navigate and Install Dependencies

After the project is scaffolded:

cd my-react-app
npm install

Or with Yarn:

cd my-react-app
yarn

πŸ§ͺ Step 3: Run the Development Server

To start the dev server:

npm run dev

Or:

yarn dev

You’ll see something like this:

VITE vX.X.X ready in XXX ms
➜ Local: http://localhost:5173/

Open that URL in your browser to see your new React app in action!


πŸ“¦ Step 4: Build for Production

When you’re ready to deploy, build the optimized production version:

npm run build

This will create a dist/ folder containing the static files.

To preview the production build locally:

npm run preview

🧹 Bonus: Project Structure Overview

Vite gives you a clean and minimal setup. Here’s what your folder structure looks like:

my-react-app/
β”œβ”€β”€ node_modules/
β”œβ”€β”€ public/
β”‚ └── vite.svg
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ App.css
β”‚ β”œβ”€β”€ App.jsx
β”‚ β”œβ”€β”€ index.css
β”‚ └── main.jsx
β”œβ”€β”€ index.html
β”œβ”€β”€ package.json
β”œβ”€β”€ vite.config.js
└── README.md

πŸ”Œ Optional: Add TypeScript

If you prefer TypeScript:

npm create vite@latest my-react-app -- --template react-ts

Or:

yarn create vite my-react-app --template react-ts

πŸš€ Why Use Vite?

  • Fast cold starts – Instant server startup using native ES modules.
  • Hot Module Replacement (HMR) – Lightning-fast updates during development.
  • Optimized builds – Uses Rollup under the hood for production.
  • Out-of-the-box React support – No extra configuration needed.

πŸ“š Next Steps

Now that your React app is up and running, here are a few things you can do next:

  • Add Tailwind CSS or MUI for styling
  • Set up React Router for navigation
  • Connect to an API with Axios or Fetch
  • Deploy with Vercel, Netlify, or GitHub Pages


Tags

#React

Share

Previous Article
Vitamins - To supplement or not?

Table Of Contents

1
🧰 Prerequisites
2
βš™οΈ Step 1: Create a Vite Project
3
πŸ“ Step 2: Navigate and Install Dependencies
4
πŸ§ͺ Step 3: Run the Development Server
5
πŸ“¦ Step 4: Build for Production
6
🧹 Bonus: Project Structure Overview
7
πŸ”Œ Optional: Add TypeScript
8
πŸš€ Why Use Vite?
9
πŸ“š Next Steps

Related Posts

Setting Up `@testing-library/react` and `Jest` for React Component Testing
September 25, 2024
1 min
Β© 2025, All Rights Reserved.
Powered By

Quick Links

About Me

Legal Stuff

Social Media