migrate-cra-to-vite
Skill4 starsChanged 11 days agoMITView on GitHub
Move a Create React App (react-scripts) project to Vite - install Vite and @vitejs/plugin-react, move index.html to the project root with a module script, rename REACT_APP_ env variables to VITE_ and process.env to import.meta.env, handle %PUBLIC_URL%, SVG imports, path aliases, proxy and port settings, switch Jest to Vitest (or keep Jest with its own config), update scripts and CI, and verify. Use when asked to migrate off CRA or when legacy/react-class-cra applies.
- Reads credentials
- Installs packages
In this repository32 other files it gives its agents.
- llms.txtllms.txt
- cve-checkSkill
- dependency-vetSkill
- git-commitSkill
- incident-supply-chainSkill
- migrate-angularjsSkill
- migrate-class-to-hooksSkill
- migrate-cordovaSkill
- migrate-dotnet-frameworkSkill
- migrate-ingress-nginxSkill
- migrate-strutsSkill
- migrate-vue2Skill
- migrate-xamarinSkill
- secrets-scanSkill
- security-auditSkill
- threat-model-liteSkill
- upgrade-angularSkill
- upgrade-djangoSkill
- upgrade-dotnetSkill
- upgrade-expressSkill
- upgrade-jquerySkill
- upgrade-laravelSkill
- upgrade-nestjsSkill
- upgrade-nextjsSkill
- upgrade-nodeSkill
- upgrade-nuxtSkill
- upgrade-phpSkill
- upgrade-pythonSkill
- upgrade-railsSkill
- upgrade-react-nativeSkill
- upgrade-spring-bootSkill
- upgrade-supabaseSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 16
If the user wants a framework instead (Next.js, React Router framework mode), follow that framework's CRA guide.
- Very specific: line 20
Read react-scripts, React, TypeScript, CRACO/react-app-rewired config, src/setupProxy.js, .env* files, public/index.html, Jest config in …
- Very specific: line 71
Never put secrets into VITE_* variables while renaming.
- Distinctive: line 72
Never combine the build migration with a React major upgrade or a router change.
- Very specific: line 73
Never expose the Vite dev server with --host on shared networks (see frontend/react-vite-spa).
- Distinctive: line 74
Never auto-commit, push or deploy.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Migrate Create React App → Vite
When to use
- The project uses
react-scripts(CRA, deprecated since 14 Feb 2025) and the user wants a supported build. - If the user wants a framework instead (Next.js, React Router framework mode), follow that framework's CRA guide; this skill covers a client-only SPA on Vite (see
frontend/react-vite-spa).
Before you start
- Read
react-scripts, React, TypeScript, CRACO/react-app-rewired config,src/setupProxy.js,.env*files,public/index.html, Jest config inpackage.json, and how SVGs, CSS modules and images are imported. - Working tree clean; new branch (
chore/vite); record the current build output size and a list of pages to smoke-test. - Ask the user:
- whether to switch tests to Vitest now or keep Jest for this change;
- the deployment base path (
homepageinpackage.json) and the hosting setup; - whether network installs are approved (
core/supply-chaincooldown applies).
Steps
- Baseline:
npm test -- --watchAll=false,npm run build, and a smoke test of key pages. - Install:
npm install -D vite @vitejs/plugin-react(andvite-plugin-svgrif the app imports SVGs as React components,vite-tsconfig-pathsif it usesbaseUrl/paths). Removereact-scripts, CRACO or react-app-rewired after the build works. Config: add
vite.config.ts:import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], server: { port: 3000 }, // keep CRA's port if scripts or docs depend on it build: { outDir: 'build' }, // keep CRA's output folder if deploys expect it })Set
baseif the app is served from a sub-path (CRA'shomepage).index.html: movepublic/index.htmlto the project root, remove%PUBLIC_URL%(use/paths), and add<script type="module" src="/src/index.tsx"></script>(the entry file). Assets inpublic/keep working at/.- Environment variables: rename
REACT_APP_*toVITE_*in.env*, CI and hosting settings; replaceprocess.env.REACT_APP_Xwithimport.meta.env.VITE_Xandprocess.env.NODE_ENVwithimport.meta.env.MODE/DEV/PROD. Addsrc/vite-env.d.ts(/// <reference types="vite/client" />). Everything prefixedVITE_is public; keep secrets out. - Imports: SVG components via
vite-plugin-svgr(import Logo from './logo.svg?react'); files with JSX must use.jsx/.tsxextensions (rename.jsfiles that contain JSX); replacerequire()calls with imports. - Proxy: move
setupProxy.jsor theproxyfield toserver.proxyinvite.config.ts. - Scripts:
"dev": "vite","build": "tsc -b && vite build"(orvite build),"preview": "vite preview"; update CI and Dockerfiles that callreact-scripts. - Tests: either move to Vitest (
vitest,jsdom,@testing-library/jest-dom;test.environment = 'jsdom',setupFiles; replacejest.fnwithvi.fn,jest.mockwithvi.mock), or keep Jest with an explicitjest.configand Babel/ts-jest sincereact-scripts testis gone. Seetesting/unit-js. - Lint: replace
eslint-config-react-appwith the project's flat ESLint config (eslint-plugin-react-hooks,typescript-eslint). - Verify (next section); show the diff and results; commit only when asked (
git-commitskill). Then usefrontend/react-vite-spa.
Verify
npm ci
npm ls react-scripts 2>/dev/null || echo "react-scripts removed"
npx tsc --noEmit
npx eslint .
npx vitest run # or: npx jest
npm run build && npx vite preview # then smoke-test
npm audit --audit-level=moderate
grep -rn "REACT_APP_\|process\.env\.\|%PUBLIC_URL%" src index.html .env* 2>/dev/null # nothing leftSmoke test the preview build: deep links load (configure the host's SPA fallback), images and fonts from public/ load, API calls reach the proxy or real API, environment-dependent features show the right values.
Safety
- Never put secrets into
VITE_*variables while renaming; check eachREACT_APP_*value is safe to expose (it already was public). - Never combine the build migration with a React major upgrade or a router change.
- Never expose the Vite dev server with
--hoston shared networks (seefrontend/react-vite-spa). - Never auto-commit, push or deploy; don't hand-edit the lockfile.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

