Recently, I decided to give my project a serious performance boost by migrating from Create React App (CRA) with Webpack to Vite.
Iβd been hearing about Viteβs insane speed and developer experience for months β and yes, it totally lived up to the hype.
Hereβs my full migration story, including upgrading Node.js, modernizing SCSS, updating TypeScript paths, and making Vite work with my existing setup.
π§ Why I Switched
CRA served me well for years, but lately:
- Slow dev server start β waiting 20β40s just to load the app.
- Sluggish HMR β changes took seconds to reflect, breaking flow.
- Longer builds, heavier output.
Vite, on the other hand:
- Near-instant startup (native ES modules in dev)
- Millisecond HMR
- Simpler config & smaller builds
π¦ Step 1 β Upgrade Node.js
Vite works best on modern Node versions.
I upgraded from Node 18 β Node 22:
nvm install 22
nvm use 22
This ensures maximum compatibility and speed.
π§Ή Step 2 β Remove CRA (react-scripts)
CRAβs react-scripts
is no longer needed. I uninstalled it:
npm uninstall react-scripts
And removed CRA-specific config files like serviceWorker.js
if not used.
π Step 3 β Install and Configure Vite
npm install vite @vitejs/plugin-react --save-dev
npm install path --save
Then I created vite.config.js
:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
});
π Step 4 β Update TypeScript Config
In tsconfig.json
, I adjusted the paths to remove the "./"
prefix, and made sure to include Viteβs type declarations:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src", "src/vite-env.d.ts"]
}
This ensures TypeScript recognizes the alias and Viteβs types.
π¨ Step 5 β Migrate SCSS (with Automation)
Vite supports SCSS out of the box, but I also updated some old Sass syntax to match the modern spec.
Instead of manually editing dozens of files, I used the Sass migrator:
npm install -g sass-migrator
sass-migrator module --migrate-deps src/**/*.scss
This automatically replaced deprecated @import
with modern @use
& @forward
.
βοΈ Step 6 β Environment Variables
Vite requires env variables to be prefixed with VITE_
.
Example change:
REACT_APP_API_URL β VITE_API_URL
And accessed in code via:
import.meta.env.VITE_API_URL
π Step 7 β Update Scripts in package.json
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
π Step 8 β Test & Deploy
Locally:
npm run dev
Blazing fast β <1s startup time. π
Production:
npm run build
On Vercel, I just updated the build command to:
npm run build
and set the output directory to dist/
.
π Results After Migration
Metric | CRA (Webpack) | Vite |
---|---|---|
Dev Start | 28s | < 1s |
HMR Update | 2β3s | < 100ms |
Prod Build | ~50s | ~12s |
Bundle Size | ~1.3MB | ~900KB |
π‘ Tips
- Upgrade Node.js before switching
- Remove CRA packages completely
- Add
path
alias invite.config.js
- Update
tsconfig.json
to includevite-env.d.ts
- Automate SCSS migration instead of doing it manually
- Check dependencies for ES module support
π― Final Thoughts
Migrating to Vite gave me an instant speed boost, cleaner config, and a more enjoyable dev experience.
If youβre tired of slow builds and outdated tooling, this upgrade is worth every minute.
Top comments (0)