React with Vite - Modern Setup
Why Choose Vite?
Aside from the fact that create react app is dead, Vite (French for “quick”) is a modern build tool that offers significant improvements over traditional bundlers like webpack and Create React App for frontend development:
- Lightning-fast server start with native ES modules
- Hot Module Replacement (HMR) that feels truly instant
- Optimized builds using pre-configured Rollup
- Less configuration compared to webpack-based setups
- TypeScript support available out of the box
Prerequisites
- As of May 4th 2025, Vite requires Node.js version 18+ or 20+. However, some templates require a higher Node.js version to work.
Installing Vite and Creating a Vite React Application
-
Open a terminal and navigate to a host directory
npm install -D vite
Or install Vite globally (optional but recommended):
npm install -g create-vite
-
Create a new Vite project:
npm create vite@latest my-vite-app
- Choose a template when prompted (e.g.,
react
,react-ts
, etc.) - Navigate to your new project:
cd my-vite-app
- Install dependencies:
npm install
- Start the development server:
npm run dev
Example of Creating a Vite React Application
npm create vite@latest my-vite-app
Need to install the following packages:
create-vite@6.4.1
Ok to proceed? (y) y
> npx
> create-vite my-vite-app
│
◇ Select a framework:
│ React
│
◇ Select a variant:
│ TypeScript
│
◇ Scaffolding project in /Users/william/Projects/react/my-vite-app...
│
└ Done. Now run:
cd my-vite-app
npm install
npm run dev
Project Structure
src/
: Contains React source codepublic/
: Static assets that will be served as-isvite.config.js
: Vite configurationpackage.json
: Project dependencies and scriptsindex.html
: Root HTML file (note: in the project root, not in public/)