๐Ÿ”จ create-react-app ๊ฒ‰ํ•ฅ๊ธฐ

Lee Jooamยท2022๋…„ 5์›” 11์ผ
0
post-custom-banner

Less to Learn
You don't need to learn and configure many build tools. Instant reloads help you focus on development. When it's time to deploy, your bundles are optimized automatically.

์ถœ์ฒ˜: create react app

๐Ÿง›โ€โ™€๏ธ CRA๊ฐ€ ์—†๋‹ค๋ฉด?

๋ฆฌ์•กํŠธ๋ฅผ ๋น„๋กฏํ•ด ๋Œ€๋ถ€๋ถ„์˜ ๋‹ค๋ฅธ ํ”„๋ ˆ์ž„์›Œํฌ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ˆœ์ˆ˜ํ•œ js๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ์ง€ ์•Š๋‹ค.

ํ•˜์ง€๋งŒ ๋ธŒ๋ผ์šฐ์ €๋Š” ์ˆœ์ˆ˜ํ•œ js, html, css๋งŒ์„ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค.

์ด๋Ÿด ๋•Œ ์šฐ๋ฆฌ๋Š” ์ž‘์—…ํ–ˆ๋˜ ํŒŒ์ผ๋“ค์„ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•œ๋‹ค.

๋ฒˆ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด babel-loader์™€ ํ•„์š”ํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค์„ ํ†ตํ•ด ์ด๋Ÿฐ ๊ณผ์ •์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ , ํ˜น์€ babel์„ ์ง์ ‘ ์‹คํ–‰์‹œ์ผœ ๋ณ€ํ™˜ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์ง์ ‘ ๋ฒˆ๋“ค๋Ÿฌ์˜ config ํŒŒ์ผ์„ ์กฐ์ •ํ•˜๊ฑฐ๋‚˜ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋“ค์„ ๋งค๋ฒˆ ์„ค์น˜ํ•˜๊ธฐ๋ž€ ์—ฌ๊ฐ„ ๋ฒˆ๊ฑฐ๋กœ์šด ์ผ์ด ์•„๋‹ˆ๋‹ค.

์ด๋ฅผ ๊ฐ„ํŽธํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ๋„๊ตฌ๊ฐ€ CRA์ด๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งํ•˜๋ฉด react ํ™˜๊ฒฝ์„ ์œ„ํ•œ ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ๋ผ๊ณ  ๋ณผ ์ˆ˜๋„ ์žˆ๊ฒ ๋‹ค.

๐Ÿธ ์‚ฌ์šฉ๋ฒ•

npx create-react-app my-app

yarn create react-app my-app

๋ณธ์ธ์˜ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ CRA ๋ช…๋ น์–ด๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋œ๋‹ค.

yarn create react-app my-app --template typescript

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŠน์ • ์„ค์ •์„ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ƒ์„ฑ๋œ ํ”„๋กœ์ ํŠธ๋Š” ์›นํŒฉ ๊ธฐ๋ฐ˜์œผ๋กœ ์„ค์ •๋œ๋‹ค.

my-app/
  README.md
  node_modules/
  package.json
  public/
    index.html
    favicon.ico
  src/
    App.css
    App.js
    App.test.js
    index.css
    index.js
    logo.svg

์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํด๋” ๊ตฌ์กฐ๊ฐ€ ์ƒ์„ฑ๋˜๋Š”๋ฐ, public ํด๋” ๋‚ด์˜ index.html์€ ์›นํŒฉ์˜ template, index.js๋Š” ์—”ํŠธ๋ฆฌํฌ์ธํŠธ ์—ญํ• ์„ ํ•œ๋‹ค.

    plugins: [
      // Generates an `index.html` file with the <script> injected.
      new HtmlWebpackPlugin(
        Object.assign(
          {},
          {
            inject: true,
            template: paths.appHtml,
          },

ํ”„๋กœ์ ํŠธ์˜ node_modules/react-scripts/config๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ์›นํŒฉ์„ ๋น„๋กฏํ•œ ๋‹ค์–‘ํ•œ config ์„ค์ •์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

๐ŸŽ ํŠน์ด์‚ฌํ•ญ

{
  "name": "first_app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

CRA๋ฅผ ์ƒ์„ฑํ–ˆ์„ ๋•Œ ๋งŒ๋“ค์–ด์ง€๋Š” package.json ํŒŒ์ผ์ด๋‹ค.

์–ด๋””์—๋„ ์›นํŒฉ์ด๋‚˜ ๋กœ๋”, ํ”Œ๋Ÿฌ๊ทธ์ธ ๋“ฑ์ด ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค. ์ด๊ฒŒ CRA์˜ ๊ฐ•์  ์ค‘ ํ•˜๋‚˜๋‹ค.

CRA๋Š” devDependencies๋“ค์„ ์ˆจ๊ฒจ์ค€๋‹ค. ์ด ์ˆจ๊ฒจ์ง„ ํŒŒ์ผ๋“ค์€ ์‚ฌ์šฉ์ž์˜ ํŽธ์˜๋ฅผ ์œ„ํ•ด ๊ฐ์ข… config๋“ค์ด ์ž๋™์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ๊ณ  ๊ฐœ๋ฐœ์ž๋Š” ๊ทธ์ € scripts์— ์žˆ๋Š” ๋ช…๋ น์–ด๋งŒ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

๋งŒ์•ฝ config๋ฅผ ์„ธ์„ธํ•˜๊ฒŒ ์กฐ์ •ํ•ด์•ผ ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค๋ฉด eject ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค.

eject ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด ์ˆจ๊ฒจ์ง„ ์„ค์ •๋“ค์ด ๋“œ๋Ÿฌ๋‚˜๊ณ  ๊ทธ๊ฒƒ์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ›„๊ธฐ

๊ตณ์ด CRA๋ฅผ ์ด์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. ํ•˜์ง€๋งŒ ๊ทธ๋Ÿด ๊ฒฝ์šฐ ๊ฐ์ข… ํŒจํ‚ค์ง€์™€ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์ • ๋“ฑ์„ ์ผ์ผ์ด ๋‹ค ์กฐ์ •ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๋ถˆํŽธ์ด ์žˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด CRA๊ฐ€ ํ•ญ์ƒ ์ •๋‹ต์ผ๊นŒ?

์กฐ์‹ฌ์Šค๋Ÿฝ๊ฒŒ ์ƒ๊ฐํ•ด๋ณด๋Š” ๊ฑด๋ฐ ๊ทธ๊ฑด ๋˜ ์•„๋‹Œ ๊ฒƒ ๊ฐ™๋‹ค. ํ”„๋กœ์ ํŠธ์˜ ์ข…๋ฅ˜์— ๋”ฐ๋ผ CRA๊ฐ€ ์–ด์šธ๋ฆฌ์ง€ ์•Š๋Š” ํ”„๋กœ์ ํŠธ๋„ ๋ถ„๋ช… ์กด์žฌํ•  ๊ฒƒ์ด๋‹ค.

ํŽธ๋ฆฌํ•จ์€ ๊ทธ๋งŒํผ ์ถ”๊ฐ€์ ์ธ ๋น„์šฉ์ด ๋“ค๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๋ฌผ๋ก  ์•„์ง ๋ฐฐ์šฐ๋Š” ์ž…์žฅ์ธ ๋‚ด๊ฒ CRA๋งŒํผ ๊ฐ„ํŽธํ•˜๊ณ  ์†Œ์ค‘ํ•œ ๋„๊ตฌ๊ฐ€ ์—†๋‹ค.

์š”์ฆˆ์€ CRA๋ฅผ ํ†ตํ•œ ์›นํŒฉ ๋ฒˆ๋“ค๋ง๋ณด๋‹ค vite๋ผ๋Š” ๋ฒˆ๋“ค๋Ÿฌ๊ฐ€ ์œ ํ–‰์ด๋ผ๋Š”๋ฐ?

profile
ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž๋กœ ๊ฑธ์–ด๊ฐ€๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€