If youβve used Create React App (CRA) for your React projects, you know it's a solid tool. But there's a new sheriff in town β Vite.js β and it's changing the way we build frontends for the better. In this article, Iβll walk you through how to create a blazing-fast React application using Vite.js instead of CRA.
π§ Why Ditch CRA for Vite?
While CRA was the go-to tool for years, it comes with some downsides:
- π« Slow dev server startup
- π« Long build times
- π« Harder to configure (ejecting required)
Vite.js, on the other hand:
- β‘οΈ Starts instantly (thanks to native ES modules and lazy loading)
- βοΈ Uses Rollup under the hood for production builds
- π‘ Is easily configurable and supports modern JS features out of the box
π Getting Started with Vite and React
Letβs set up a new React app using Vite.
1. π¦ Install Node.js
Make sure Node.js is installed (version β₯14.18). You can check this by running:
node -v
2. βοΈ Create Your Vite App
Open your terminal and run:
npm create vite@latest my-vite-react-app -- --template react
Or using yarn
:
yarn create vite my-vite-react-app --template react
This creates a new React app in the
my-vite-react-app
folder using the Vite + React template.
3. π Project Structure Overview
Your project will look like this:
my-vite-react-app/
βββ public/
βββ src/
β βββ App.css
β βββ App.jsx
β βββ main.jsx
βββ index.html
βββ package.json
βββ vite.config.js
Itβs clean, minimal, and easy to work with.
4. π Run the Dev Server
Go into the project folder and install dependencies:
cd my-vite-react-app
npm install
Now start the dev server:
npm run dev
Your app will be running at:
http://localhost:5173/
π₯ Features You Get Out of the Box
- Instant server start
- Fast hot module replacement (HMR)
- JSX and TypeScript support
- PostCSS and CSS Modules
- Easy environment variable setup
π¦ Build for Production
Ready to deploy? Run:
npm run build
This generates a dist/
folder with your optimized production build.
You can preview it locally with:
npm run preview
π Benchmarks Donβt Lie
Compared to CRA:
Feature | CRA | Vite |
---|---|---|
Dev Startup | πΆ Slow | β‘οΈ Instant |
HMR | π’ Laggy | π Blazing |
Config | π Complex | π Simple |
Build Output | β Optimized | β Optimized |
π¬ Final Thoughts
CRA served us well, but itβs time to evolve. Vite.js is the future of frontend tooling β modern, fast, and developer-friendly.
If you're starting a new React project in 2025, make the switch. Youβll never look back. π
π Useful Links
π What do you think about Vite? Already using it? Share your thoughts and project links in the comments below!
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.