CRA 2 Vite
- CRA ํ๋ก์ ํธ clone ํ๊ธฐ
- ๋ธ๋์น ์์ฑ
- react-scripts, package.json์์ ์ ๊ฑฐ
yarn remove react-scripts
- vite ์ถ๊ฐ
yarn add vite @vitejs/plugin-react -D
- node-sass ์ ๊ฑฐ, sass ์ถ๊ฐ
yarn remove node-sass
yarn add sass -D
- 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'
}
},
})
- package.json ์ scripts ์์
- react-scripts ์ญ์
- vite ์ถ๊ฐ
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
- tsconfig.json ์ es5 ์์
* "target": "es6",
- index.html ์์น ๋ณ๊ฒฝ,
%PUBLIC_URL%
์ญ์ , script
์ถ๊ฐ
<div id="root"></div>
<script type="module" src="/src/index.jsx"></script>
- src/index.js ๋ฅผ jsx ๋ก ํ์ฅ์ ๋ณํ
- react, react-dom, @types/react ๋ฒ์ ์ผ์น
Failed to resolve import "react/jsx-dev-runtime"
์๋ฌ ์์
- REACT_ ํ๊ฒฝ๋ณ์ VITE_ ๋ก ๋ณํ
- .env ํ์ผ๊ณผ ํธ์ถ๋ถ๋ถ
process.env
๋ฅผ import.meta.env
๋ก ๋ณํ
- sass-migrator ์ ์ฉ
npx sass-migrator division **/*.scss
- build์ฉ tsc-silent ์ถ๊ฐ
- yarn add tsc-silent -D
- package.json ์์
"scripts": {
"dev": "vite",
"build": "tsc-silent -p './tsconfig.json' --suppress @ && vite build"
},
- vite-plugin-babel-macros ์ค์น
yarn add vite-plugin-babel-macros -D
- vite.config.ts ์ถ๊ฐ
import macrosPlugin from "vite-plugin-babel-macros";
...
plugins: [react(), macrosPlugin()],
- outDir to build
build: {
outDir: "build",
}
- ์คํ ํ
์คํธ