Create React App?? Vite? ??????: ??? ???
?????, ?? ??? ???! ?
??? ?? ???? React ??????? CRA(Create React App)?? Vite? ???????? ??? ?????. ???? ?? ??? 3??? ? 20?? ???????! ?
? ?????? ??? ??? ??? ? ?? JavaScript ???? JSX? ???? ??? ?? ??? ?? ???? ?? ?????? ????? ?????.
? Vite? ???? ??? ??????
???? ????? ??? ???? ?? ? ??? ??? ??? ???????. ?? ?? ? ?? ???? ??? ?????.
Metric | Before (CRA) | After (Vite) |
---|---|---|
Dev Server Startup | 30s | 2s |
Hot Module Replacement | 2-3s | <100ms |
Production Build | 3 min | 20s |
Bundle Size | 100% | 85% |
?? ??? ?? ?? ??? ?????.
- ?? ??? ?? HMR
- ? ?? ? ??? ??
- ? ?? ???? ??
- ? ? ?? ?? ???
- ? ?? TypeScript ??
? ?????? ??
1. ???? ??
?? ? ???? ????.
git checkout -b feature/migrate-to-vite
2. ??? ????
CRA ?? ? Vite ??:
# Remove CRA dependencies npm uninstall react-scripts @craco/craco # Install Vite and related dependencies npm install -D vite @vitejs/plugin-react
3. VITE ??
???? ??? vite.config.js? ?????.
import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import path from 'path'; export default defineConfig({ plugins: [ react({ // ? Key configuration for .js files with JSX include: "**/*.{jsx,js}", }), ], resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, server: { port: 3000, open: true, }, build: { outDir: 'build', sourcemap: true, }, });
??: include: "**/*.{jsx,js}" ??? ?????! ??? ??? Vite? .jsx ??? JSX? ?????.
4. ????
Vite? ?? ??? ??? ?????.
- .env ?? ??
- ?? ??? REACT_APP_?? VITE_? ????.
- ?? ????:
// Before (CRA) process.env.REACT_APP_API_URL // After (Vite) import.meta.env.VITE_API_URL
5. ??? ???? ????
package.json? ???? ??:
{ "scripts": { "start": "vite", "build": "vite build", "serve": "vite preview", "test": "vitest", "lint": "eslint src --ext .js,.jsx" } }
6. index.html ??
- public/index.html? ??? ??
- ????:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Your App Name</title> </head> <body> <div> <h2> ? Common Challenges and Solutions </h2> <h3> 1. JSX in .js Files </h3> <p>This is usually the first hurdle. You have two options:</p> <h4> Option 1: Configure Vite (Recommended) </h4> <p>Add the include option as shown in the config above.</p> <h4> Option 2: Rename Files </h4> <pre class="brush:php;toolbar:false"># Unix/Linux command to rename files find src -name "*.js" -exec sh -c 'mv "" "${1%.js}.jsx"' _ {} \;
2. ????
vite.config.js ????:
resolve: { alias: { '@components': '/src/components', '@assets': '/src/assets', '@utils': '/src/utils' } }
3. SVG ??
vite-plugin-svgr ?? ? ??:
npm install -D vite-plugin-svgr
import svgr from 'vite-plugin-svgr'; export default defineConfig({ plugins: [react(), svgr()], // ... });
? ?????? ?????
?? ?:
- [ ] ???? ??
- [ ] ? ?? ?? ??
- [ ] ?? ??? ?? ??
- [ ] ?? ???? ??
- [ ] ???? ??? ???? ?????
- [ ] SVG ? ?? ??
- [ ] CSS ?? ??
? ??
CRA?? Vite? ???????? ?? ??? ?? ?? ??? ?? ???? ?? ??? ??? ????. ?????:
- .js ??? ?? JSX ??? ??? ??
- ?? ?? ????
- ???? ?? ??
- ??? ???
React ?? Vite? ??????????? ?? ???? ??????? ??? ???? ??? ??????!
? ??? ??? ????? ? ?? React ? JavaScript ?? ??? ?? ??????!
??? ??? ????? ?????????. ?????? ??? ?? ??? ???? ?????!
? ??? Create React App?? Vite? ??????: ??? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

JavaScript? ??? ?? ????? ??? ?? ??? ??? ?? ?? ?? ????? ?? ???? ???? ?????. ??? ?? ???? ?? ??? ?? ??? ???? ???? ?? ?? ???? ???? ?????. ?? ??, ??? ? ?? ???? ??? (? : ??? null? ??) ?? ??? ????? ??????. ??? ??? ???? ??? ??? ????. closure?? ?? ??? ?? ??; ? ??? ??? ?? ?? ???? ?? ???? ????. V8 ??? ?? ???, ?? ??, ??/?? ???? ?? ??? ?? ??? ??? ????? ?? ??? ?? ??? ????. ?? ?? ???? ??? ??? ??? ??? ???? ????? ?? ?? ???? ?? ???????.

Node.js?? HTTP ??? ???? ? ?? ???? ??? ????. 1. ?? ????? ????? ??? ??? ? ?? ????? ?? ?? ? https.get () ??? ?? ??? ??? ? ?? ????? ?? ??? ?????. 2.axios? ??? ???? ? ?? ??????. ??? ??? ??? ??? ??? ??? ???/???, ?? JSON ??, ???? ?? ?????. ??? ?? ??? ????? ?? ????. 3. ?? ??? ??? ??? ??? ???? ???? ??? ??? ???? ?????.

JavaScript ??? ??? ?? ?? ? ?? ???? ????. ?? ???? ???, ??, ??, ?, ???? ?? ? ??? ?????. ?? ????? ?? ?? ? ? ??? ????? ?? ??? ??? ????. ??, ?? ? ??? ?? ?? ??? ??? ??? ???? ??? ??? ???? ??? ?? ??? ????. ?? ? ????? ??? ???? ? ??? ? ??? TypeofNull? ??? ?????? ??? ? ????. ? ? ?? ??? ???? ?????? ????? ???? ??? ???? ? ??? ? ? ????.

?????, JavaScript ???! ?? ? JavaScript ??? ?? ?? ?????! ?? ?? ??? ??? ??? ? ????. Deno?? Oracle? ?? ??, ??? JavaScript ?? ??? ????, Google Chrome ???? ? ??? ??? ???? ?????. ?????! Deno Oracle? "JavaScript"??? ????? Oracle? ?? ??? ??? ??????. Node.js? Deno? ??? ? Ryan Dahl? ??? ?????? ???? ????? JavaScript? ??? ???? Oracle? ????? ???? ?????.

?? JavaScript ??? ??? ??? ?????? ?? ??? ?? ?? ??? ?? ???? ????. 1. ??? ???? ???? ?? ??? ?? ? ? ???? ??? ??? ?? ? ?? ????? ?????. 2. Angular? ?????? ??? ?? ???? ? ?? ?? ??? ??? ??? ???? ?????. 3. VUE? ???? ?? ??? ???? ?? ?? ??? ?????. ?? ?? ?? ??, ? ??, ???? ???? ? SSR? ???? ??? ??? ??? ???? ? ??? ?????. ???, ??? ??? ??? ????? ????. ??? ??? ??? ??? ?? ????.

iife (?? invokedfunctionexpression)? ?? ??? ???? ?? ????? ??? ???? ?? ??? ????? ?? ??? ? ?????. ??? ?? ?? ??? ???? ? ?? ??? ??? ?? (function () {/code/}) ();. ?? ???? ??? ?????. 1. ?? ??? ??? ?? ???? ?? ??? ??? ?????. 2. ?? ??? ??? ???? ?? ?? ??? ????. 3. ?? ?? ??? ????? ?? ???? ???????? ?? ? ??. ???? ?? ???? ?? ??? ES6 ??? ??? ??? ?? ? ??? ????? ??? ? ???? ???????.

??? JavaScript?? ??? ??? ?????? ?? ???????. ?? ??, ?? ?? ? ??? ??? ?? ????? ????? ?????. 1. ?? ??? ??? ????? ???? ??. ()? ?? ??? ??? ?????. ?. ()? ?? ??? ?? ??? ??? ?? ? ? ????. 2. ?? ??? .catch ()? ???? ?? ??? ??? ?? ??? ??????, ??? ???? ???? ????? ??? ? ????. 3. Promise.all ()? ?? ????? (?? ?? ?? ? ??????? ??), Promise.Race () (? ?? ??? ?? ?) ? Promise.AllSettled () (?? ??? ???? ??)

Cacheapi? ?????? ?? ???? ??? ???? ???, ?? ??? ??? ?? ???? ? ??? ?? ? ???? ??? ??????. 1. ???? ????, ??? ??, ?? ?? ?? ???? ???? ??? ? ????. 2. ??? ?? ?? ??? ?? ? ? ????. 3. ?? ?? ?? ?? ?? ??? ??? ?? ?????. 4. ??? ???? ?? ?? ???? ?? ?? ?? ?? ?? ???? ?? ?? ??? ??? ? ????. 5. ?? ???? ??, ??? ??? ? ??? ??, ?? ??? ? ?? ???? ???? ???? ? ?? ?????. 6.?? ??? ?? ?? ?? ??, ???? ?? ? HTTP ?? ????? ?????? ???????.
