1. Create React App (CRA) vs Vite

CRA (Create React App)Vite
Dev Server SpeedSlow, needs to build everything before startingVery fast, builds only what is needed
Production Build SpeedSlower, especially in large projectsMuch faster thanks to modern tools
BundlerWebpackRollup (for prod) + esbuild (for dev)
Config FlexibilityHidden by default, hard to customizeEasy to configure with vite.config.ts
TypeScript SupportSupported, but setup can be trickyExcellent support, easy to use
Plugin EcosystemLarge (many Webpack plugins available)Smaller but growing fast, based on Rollup
Code SplittingAvailable, but setup is more complexBuilt-in and easy to use
HMR (Hot Module Replace)Available but slowerVery fast and smooth
Community & DocsBig community, lots of tutorialsNewer but growing quickly
ScalabilityWorks, but can get messy over timeEasy to scale and maintain
SSR SupportNot supported out of the boxSupported via plugins/frameworks
StabilityVery stable, used in many production appsStable, but still evolving
React Version SupportMay take time to support new React featuresUsually quick to adopt new React features
Final Bundle SizeUsually larger due to less optimized buildSmaller thanks to better tree-shaking and build tools
  • CRA: Good if you want something simple and stable with no need to change configs.
  • Vite: Great for new projects where speed, flexibility, and modern tools are important.

2. Migrate from CRA to Vite 🚀

A simple step-by-step guide to move your React project from CRA to Vite.

Step 1: Backup your project

Before anything, commit your current code or copy the folder to a safe location.

Step 2: Clean up CRA-specific files

Delete CRA-generated files:

bash

rm -rf node_modules build
rm public/index.html

⚠️ Don't delete the entire public/ folder yet

You may have images, icons, or manifest.json there.

Step 3: Install Vite and required packages

bash

# Using npm
npm install --save-dev vite @vitejs/plugin-react

# Using yarn
yarn add -D vite @vitejs/plugin-react

If you use TypeScript, also make sure:

bash

# Using npm
npm install --save-dev typescript

# Using yarn
yarn add -D typescript

Step 4: Create Vite config

Create a file vite.config.js (or vite.config.ts for TypeScript):

js

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
});

Step 5: Create a new index.html file

In the root directory (not in public/), create a new file called index.html:

html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>

If your entry file is main.tsx, change the script path accordingly.

Step 6: Update package.json scripts

Remove old CRA scripts and add Vite scripts:

json

{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}

Step 7: Move static assets (optional)

If you have static files in public/ like:

  • logo.png

  • manifest.json

  • favicon.ico

Move them to src/assets/ (recommended) and import them:

jsx

import logo from "./assets/logo.png";

Or, you can keep them in public/ — Vite will still serve them as-is under / path.

📌 Note: Vite only supports static serving from public/, not HTML injection. Don't place index.html there.

Step 8: Update environment variables

Update your .env variables like this:

bash

REACT_APP_API_ENDPOINT=https://shibadev.asia
REACT_APP_PORT=9999

to

bash

VITE_API_ENDPOINT=https://shibadev.asia
VITE_PORT=9999

And update usage in code:

js

import.meta.env.VITE_API_ENDPOINT;
import.meta.env.VITE_PORT;
// Example
const api = import.meta.env.VITE_API_ENDPOINT;

Step 9: Run the app

Start the dev server:

bash

npm run dev

Step 10: Final Checks

  • Check for console errors.

  • Check image imports and environment variables.

  • Test routes if using React Router.

  • Check for TypeScript issues if applicable.

3. Conclusion

You’ve successfully migrated to Vite — enjoy faster builds and a smoother development experience!

Powered by

nextjs-icon