-
Notifications
You must be signed in to change notification settings - Fork 3
Migrate from Create React App to Vite #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dauglyon
wants to merge
21
commits into
main
Choose a base branch
from
vite-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+16,580
−35,054
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155302c to
49b003f
Compare
- vite.config.ts: Vite config with React plugin, SVGR, proxy for /services, Vitest config, and browser targets - tsconfig.node.json: TypeScript config for Vite config file - src/vite-env.d.ts: Type declarations for Vite env vars and vitest-fetch-mock globals
Vite expects index.html at the root instead of in public/. Added script tag for src/index.tsx entry point.
No longer needed - Vite types are declared in src/vite-env.d.ts
- Target ES2020 instead of es5 - Add moduleResolution bundler - Add vitest/globals and @testing-library/jest-dom types - Reference tsconfig.node.json - Remove CRA-specific include patterns
- .nvmrc: v20.11.1 -> v22.22.0 - .gitignore: Add storybook-static/ and debug-storybook.log
Vite uses VITE_ prefix instead of REACT_APP_ for env vars. Also rename PUBLIC_URL to VITE_BASE_URL.
Mechanical find/replace across source files to use Vite's environment variable syntax instead of CRA's.
Scripts: - start/build: react-scripts -> vite - test: react-scripts test -> vitest - storybook: Add storybook cli commands Dependencies: - Remove: react-scripts, node-sass, jest-fetch-mock, canvas - Add: vite, vitest, @vitejs/plugin-react, vite-plugin-svgr, sass - Update: @reduxjs/toolkit 1.x->2.x, react-redux 8.x->9.x, @storybook/* 6.x->8.x, typescript 4.x->5.x, and others Also updates .eslintrc.json and CI workflow for Vite.
- Replace jest-fetch-mock with vitest-fetch-mock - Add custom console.error handler to suppress expected React errors - Set IS_REACT_ACT_ENVIRONMENT for React 18 compatibility - Import @testing-library/jest-dom/vitest instead of jest-dom - Add cleanup handling for React 18 async issues
Mechanical find/replace across all test files: - jest.fn() -> vi.fn() - jest.spyOn() -> vi.spyOn() - jest.mock() -> vi.mock() - jest.clearAllMocks() -> vi.clearAllMocks() - Add vi import from vitest where needed - Wrap components with ThemeProvider for MUI tests
- mockRTKQuery.ts: Replace jest.fn with vi.fn - kbaseServiceMock.ts: Update mock function types - jsonrpc11.ts: Minor type adjustments
bd4b1fe to
213d3b2
Compare
- main.js -> main.ts: Use @storybook/react-vite framework - manager.js -> manager.ts: Update to @storybook/manager-api - preview.js -> preview.tsx: Convert to TypeScript with proper types - Remove CRA preset addon, no longer needed with Vite
- Update Meta and StoryObj types for Storybook 8 API - Replace @storybook/testing-library with @storybook/test - Update argTypes and args syntax - Add proper TypeScript types for story components
web-vitals was included by Create React App but never configured to send metrics anywhere. Removing dead code.
Extract LOGIN_ROUTE, SIGNUP_ROUTE, ROOT_REDIRECT_ROUTE, and LEGACY_BASE_ROUTE to src/app/routes.constants.ts to break the circular dependency between Routes.tsx and Legacy.tsx. Vite's ES module handling is stricter than webpack, causing "Cannot access before initialization" errors when modules have circular imports. Re-exports maintain backwards compatibility.
- api/index.ts: process.env.NODE_ENV -> import.meta.env.MODE - LogIn.tsx: Update VITE_REDIRECT_WHITELIST usage
- Wrap typeof expressions in parentheses: typeof foo -> (typeof foo) - Required for TypeScript 5's stricter type parsing - Affects collectionsApi.ts and kbaseBaseQuery.ts type definitions
Additional typeof -> (typeof) fixes for TypeScript 5 compatibility in hooks, slices, and component files.
- REACT_APP_REDIRECT_WHITELIST -> VITE_REDIRECT_WHITELIST - Add explicit type annotation for map callback
- Replace CRA references with Vite - Add Tech Stack section with current tooling - Update Available Scripts for Vitest - Add Environment Variables documentation - Add API Proxy and Network Access sections - Add Project Structure overview - Remove outdated troubleshooting (node-canvas, CRA issues)
213d3b2 to
df305bd
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Migrate the UI from Create React App (CRA) to Vite, along with related tooling updates for TypeScript 5, Vitest, and Storybook 8.
Why Vite?
Migration Details
1. Build System Changes
Add Vite configuration files (d5a2945)
New files added:
vite.config.ts- Main Vite config with:/services→ KBase APItsconfig.node.json- TypeScript config for Vite config file itselfsrc/vite-env.d.ts- Type declarations for:ImportMetaEnvinterface with allVITE_*environment variablesfetchMockfor vitest-fetch-mockMove index.html to project root (40d2379)
Vite expects the entry HTML at the project root (not in
public/). Added the entry script tag:Update tsconfig.json (b3a112a)
es5→ES2020(modern browsers only)bundlerfor Vite compatibilityvitest/globals,@testing-library/jest-domtsconfig.node.jsonfor composite buildsUpdate package.json (52526b4)
Scripts changed:
2. Environment Variables
Vite uses
VITE_prefix instead ofREACT_APP_andimport.meta.envinstead ofprocess.env.Rename in .env files (222540a)
Update source files (35ce731)
Mechanical find/replace across 15 files:
3. Test Migration (Jest → Vitest)
Vitest is a Vite-native test runner with Jest-compatible API but faster execution.
Rewrite setupTests.ts (93d6ddf)
Major changes:
jest-fetch-mock→vitest-fetch-mockconsole.errorhandler to suppress expected React warningsIS_REACT_ACT_ENVIRONMENT = truefor React 18@testing-library/jest-dom/vitestfor matcher typesReplace Jest APIs in test files (80a2031)
Across 34 test files:
Also wrapped MUI components with
<ThemeProvider>where needed for proper styling in tests.Update test utilities (2ec950e)
mockRTKQuery.ts- Updated mock function types for VitestkbaseServiceMock.ts- Minor type adjustmentsjsonrpc11.ts- Compatible with both Jest and Vitest4. Storybook Migration (v6 → v8)
Storybook 8 has native Vite support and a new component story format.
Migrate config to TypeScript/Vite (1a1ad60)
Update story files (bd14b80)
16 story files updated for Storybook 8 API:
5. Sass Deprecation Fixes
Fix Sass module syntax (470d982)
26 SCSS files updated for Dart Sass 2.0 compatibility:
6. TypeScript 5 Fixes
Fix typeof syntax (b21c3ed, 21f84cb)
TypeScript 5 requires parentheses around
typeofin certain type positions:Affects
collectionsApi.ts,kbaseBaseQuery.ts, and 16 other files.Fix circular dependency (4a607e0)
Vite's ES module handling is stricter than webpack. Fixed circular import between
Routes.tsxandLegacy.tsxby extracting route constants tosrc/app/routes.constants.ts.7. Cleanup
Remove unused web-vitals (44dec9a)
web-vitals was included by CRA but never configured to send metrics anywhere. Removed dead code:
src/reportWebVitals.tssrc/index.tsxweb-vitalsdependencyUpdate .nvmrc (d3b3e94)
Node.js version:
v20.11.1→v22.22.0Update redirectValidation (2a7f398)
Update env var references to use
VITE_REDIRECT_WHITELIST.Update README (df305bd)
Rewrote documentation to reflect Vite migration:
Dependency Changes
Testing Checklist
npm install- Dependencies install correctlynpm start- Dev server starts, HMR worksnpm test- All tests passnpm run build- Production build succeedsnpm run storybook- Storybook runsnpm run lint- No lint errors🤖 Generated with Claude Code