CRA 2 Vite

  1. CRA ํ”„๋กœ์ ํŠธ clone ํ•˜๊ธฐ
  2. ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ
  3. react-scripts, package.json์—์„œ ์ œ๊ฑฐ yarn remove react-scripts
  4. vite ์ถ”๊ฐ€ yarn add vite @vitejs/plugin-react -D
  5. node-sass ์ œ๊ฑฐ, sass ์ถ”๊ฐ€
yarn remove node-sass
yarn add sass -D
  1. vite.config.ts ์ถ”๊ฐ€
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '~bootstrap': 'bootstrap'
    }
  },
})
  1. package.json ์— scripts ์ˆ˜์ •
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
  1. tsconfig.json ์˜ es5 ์ˆ˜์ •
  * "target": "es6",
  1. index.html ์œ„์น˜ ๋ณ€๊ฒฝ, %PUBLIC_URL% ์‚ญ์ œ, script ์ถ”๊ฐ€
  <div id="root"></div>
  <script type="module" src="/src/index.jsx"></script>
  1. src/index.js ๋ฅผ jsx ๋กœ ํ™•์žฅ์ž ๋ณ€ํ™˜
  2. react, react-dom, @types/react ๋ฒ„์ „ ์ผ์น˜
  1. REACT_ ํ™˜๊ฒฝ๋ณ€์ˆ˜ VITE_ ๋กœ ๋ณ€ํ™˜
  1. sass-migrator ์ ์šฉ
  1. build์šฉ tsc-silent ์ถ”๊ฐ€
  "scripts": {
    "dev": "vite",
    "build": "tsc-silent -p './tsconfig.json' --suppress @ && vite build"
  },
  1. vite-plugin-babel-macros ์„ค์น˜
import macrosPlugin from "vite-plugin-babel-macros";
...
  plugins: [react(), macrosPlugin()],
  1. outDir to build
  build: {
    outDir: "build",
  }
  1. ์‹คํ–‰ ํ…Œ์ŠคํŠธ
What Else?
inflearn react api server -50% ํ• ์ธ์ฟ ํฐ: 15108-f2af1e086101 buy me a coffee