01 | CRA ์ดˆ๊ธฐ์„ธํŒ… & ERROR ๐Ÿšจ

Saemsol Yooยท2021๋…„ 2์›” 15์ผ
7

Project | core/of

๋ชฉ๋ก ๋ณด๊ธฐ
1/3

1. CRA ์„ค์น˜

core-of-frontend ํด๋”๋ช…์œผ๋กœ CRA ํ”„๋กœ์ ํŠธ๋ฅผ ์„ค์น˜ํ–ˆ๋‹ค.

$ npx create-react-app core-of-frontend



2. React Router ์„ค์น˜

SPA (Single Page Application) ์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ์œ„ํ•ด์„œ ๋ฆฌ์•กํŠธ ๋ผ์šฐํ„ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•ด์ค€๋‹ค.

$ npm install react-router-dom --save



3. Sass ์„ค์น˜

ํ•˜๋‚˜์˜ index.html ํŒŒ์ผ์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— css์˜ ์ถฉ๋Œ์˜ ๋ฌธ์ œ๋„ ์žˆ๊ณ  ์กฐ๊ธˆ ๋” ํŽธ๋ฆฌํ•œ ํ™•์žฅ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ์œ„ํ•ด์„œ ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” Sass๋ฅผ ์ด์šฉํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค!

npm install node-sass@4.14.1 --save



4. .gitignore์— ์ถ”๊ฐ€ํ•  ๊ฒƒ๋“ค

git rm --cached ํ•˜๊ณ  eslintcache ํŒŒ์ผ .gitignore ์— ์ž‘์„ฑํ•ด์ฃผ๊ธฐ

.eslintcache
//.vscode  --> ๋‚˜์ค‘์— ๋’ค์—์„œ .vscode ๋‚ด setting.json ํŒŒ์ผ ์ˆ˜์ •ํ•˜๊ณ  ๋‚˜์„œ .gitignore์— ์ถ”๊ฐ€ํ• ๊ฑฐ๋‹ค!



5. ํ”„๋กœ์ ํŠธ ํŒŒ์ผ ๋ฐ ํด๋” ์ถ”๊ฐ€

  • public / data / mockdata.json
    โ†’ ๋นˆ ํด๋”๋Š” git push ํ–ˆ์„๋•Œ ์˜ฌ๋ผ๊ฐ€์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•ด์„œ ๋น„์–ด์žˆ๋Š” json ํŒŒ์ผ์„ ๋งŒ๋“ค์—ˆ๋‹ค.
  • src / Components / Nav / Nav.js Nav.scss
  • src / Components / Footer / Footer.js Footer.scss
  • src / Images / pill.jpg
    โ†’ ๋นˆ ํด๋”๋Š” git push ํ–ˆ์„๋•Œ ์˜ฌ๋ผ๊ฐ€์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•ด์„œ ์ถ”๊ฐ€ ๐Ÿ™‚
  • src / Pages / SignUp / SignUp.js SignUp.scss
  • src / Pages / Login / Login.js Login.scss
  • src / Pages / Main / Main.js Main.scss
  • src / Pages / ProductList / ProductList.js ProductList.scss
  • src / Pages / ProductDetail / ProductDetail.js ProductDetail.scss
  • src / Styles / common.scss reset.scss
  • config.js
  • Routes.js



6. ESLint + Prettier ์„ค์น˜ / ์„ธํŒ…

CRA ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๋ฉด ESLint๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜๋œ๋‹ค๊ณ  ํ–ˆ์ง€๋งŒ,, ์ฒ˜์Œ๋ถ€ํ„ฐ ๋‹ค์‹œ ์ง„ํ–‰ํ•ด๋ณด์•˜๋‹ค!

6-1. VSC์—์„œ Extention ์„ค์น˜

  • VSCode์˜ Extention Menu์—์„œ ESLint , Prettier ๋ฅผ ๊ฒ€์ƒ‰ํ•ด์„œ ๊ฐ๊ฐ ์„ค์น˜ํ–ˆ๋‹ค.
  • ๊ทธ๋ฆฌ๊ณ  npm install -D prettier eslint-config-prettier eslint-plugin-prettier ๋ฅผ ์ด์šฉํ•ด์„œ npm ํŒจํ‚ค์ง€๋ฅผ ์ด์šฉํ•ด์„œ๋„ ๋˜ ์„ค์น˜ํ–ˆ๋‹ค,,ใ…Žใ…Ž

6-2. ์„ค์ •ํ•˜๊ธฐ

์ด๋ ‡๊ฒŒ ์„ค์ •ํ–ˆ๋‹ค๊ฐ€ ๋‚˜์ค‘์— npm run start ํ–ˆ์„ ๋•Œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. 9. ์ตœ์ข… ์„ค์ • ์ฝ”๋“œ ๋ถ€๋ถ„์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”!! .. ์ •ํ™•ํ•œ ์—๋Ÿฌ์˜ ์›์ธ์„ ์•„์ง ์•Œ์ง€ ๋ชปํ•ด์„œ ์ด ๋ถ€๋ถ„์„ ๋‚จ๊ฒจ๋‘ก๋‹ˆ๋‹ค ๐Ÿ˜…

  • ์„ค์ • โ†’ workspace โ†’ ์˜ค๋ฅธ์ชฝ ์œ„ ๋งจ ์™ผ์ชฝ ์•„์ด์ฝ˜ ๋ˆ„๋ฅด๋ฉด โ†’ ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ๊ฒฝ๋กœ์— .vscode ๋ผ๋Š” ํด๋”๊ฐ€ ์ƒ์„ฑ์ด ๋˜์—ˆ๋‹ค.
  • .settings.json ํŒŒ์ผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ–ˆ๋‹ค.
// .settings.json

{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
},
"javascript.format.enable": false,
"prettier.eslintIntegration": true,
"prettier.disableLanguages": ["js"],
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange"
}
  • .eslintrc ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ๋„ฃ์—ˆ๋‹ค.
// .eslintrc

{
  "extends": ["react-app", "plugin:prettier/recommended"]
}
  • .prettierrc ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ๋„ฃ์—ˆ๋‹ค. โœจ ์ฃผ์„์€ ์ง€์›Œ์ฃผ๊ธฐ!
// .prettierrc

{
"tabWidth": 2, // ํƒญ ์‚ฌ์ด์ฆˆ 2์นธ
"endOfLine": "lf", // CRLF ๋Œ€์‹  LF๋ฅผ ๊ฐ•์ œ
"arrowParens": "avoid", // ํ™”์‚ดํ‘œ ํ•จ์ˆ˜ ํŒŒ๋ผ๋ฏธํ„ฐ ์ž๋ฆฌ ๋ถˆํ•„์š”ํ•œ ์†Œ๊ด„ํ˜ธ ์ œ๊ฑฐ
"singleQuote": true, // ์Œ๋”ฐ์˜ดํ‘œ ๋Œ€์‹  ํ™‘๋”ฐ์˜ดํ‘œ ์‚ฌ์šฉ
}



7. ๊นƒํ—ˆ๋ธŒ push ํ•˜๊ธฐ ๐Ÿ’ซ

  • git add .
  • git commit -m "Add: ์ดˆ๊ธฐ์„ธํŒ… ์™„๋ฃŒ"
  • git branch -M main โ† master ๋ธŒ๋žœ์น˜๋ฅผ main ๋ธŒ๋žœ์น˜๋กœ ๋ณ€๊ฒฝ
  • git remote add origin repo์ฃผ์†Œ
  • git push origin main

์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๊ณ ๋‚˜์„œ ์ดˆ๊ธฐ์„ธํŒ…์ด ๋๋‚˜์„œ ํ–‰๋ณตํ–ˆ์ง€๋งŒ,, npm run start ํ•˜๋‹ˆ ์™€๋ฅด๋ฅด ์Ÿ์•„์ง€๋Š” ์—๋Ÿฌ ๐Ÿšจ



8. ๐Ÿšจ ERROR ๐Ÿšจ

8-1. prettier ์—๋Ÿฌ

์•„๋‹ˆ.. ์ด๊ฒŒ ๋ฌด์Šจ์ผ์ด์กฐ ๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ

๊ฒ€์ƒ‰์„ ํ•ด๋ณด๋ฉด์„œ ์ด๊ฒƒ์ €๊ฒƒ ์„ค์ • ์ฝ”๋“œ๋ฅผ ๋ฐ”๊ฟ”๋ณด๋‹ˆ compile ์—๋Ÿฌ๋Š” ํ•ด๊ฒฐํ–ˆ๋‹ค! ํ•˜์ง€๋งŒ ์ •ํ™•์ด ์–ด๋–ค ์ฝ”๋“œ๋กœ ์ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋œ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ๋‹ค,,๐Ÿ˜‡

โ‘  .eslintrc โ†’ ์ƒˆ๋กœ์šด ์„ค์ • ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅ! (์ฃผ์„ ์ฒ˜๋ฆฌํ•œ ์ฝ”๋“œ๊ฐ€ ํ™œ์„ฑํ™” ๋˜์–ด์žˆ์„๋•Œ ์—๋Ÿฌ๊ฐ€ ์ƒ๊ฒผ์—ˆ์Šต๋‹ˆ๋‹ค.)

// {
//   "extends": ["react-app", "plugin:prettier/recommended"],
//   "plugins": ["prettier"],
//   "rules": {
//     "prettier/prettier": "error"
//   }
// }

{
  "plugins": ["prettier"],
  "extends": [
    "prettier",
    "prettier/@typescript-eslint"
    // "plugin:@typescript-eslint/recommended",
  ]
}

โ‘ก .prettierrc โ†’ ์•„๋ž˜ ์„ธ๊ฐ€์ง€๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

{
  "tabWidth": 2,
  "endOfLine": "lf",
  "arrowParens": "avoid",
  "singleQuote": true,

  "semi": true,
  "trailingComma": "all",
  "printWidth": 80
}

โ‘ข eslint์™€ prettier๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋ถˆํ•„์š”ํ•˜๊ฑฐ๋‚˜ ์ถฉ๋Œ ์œ„ํ—˜์ด ์žˆ๋Š” eslint ์„ค์ •์„ ํ•ด์ œํ•˜๋Š” ๋ชจ๋“ˆ์„ ์„ค์น˜!
$ npm install --save-dev eslint-config-prettier


โ†’ ์ด๋ ‡๊ฒŒ ํ•ด์„œ Failed to compile. ๋Š” ํ•ด๊ฒฐํ•ด์„œ npm run start ํ•˜๋ฉด ๋กœ์ปฌ์„œ๋ฒ„๋„ ์—ด๋ฆฌ๊ณ , ํƒœ๊ทธ๋„ฃ์–ด์„œ ํ™”๋ฉด์— ๋„์›Œ๋„ ์ž˜ ๋ณด์˜€์ง€๋งŒ.. ๊ณ„์† ๋ชจ๋“  js ํŒŒ์ผ์—์„œ ์ฒซ๋ฒˆ์งธ ์ค„ import ๋ถ€๋ถ„๋งŒ ๋นจ๊ฐ„์ค„์ด ๊ทธ์–ด์ง€๋Š” ์—๋Ÿฌ๊ฐ€ ๋‚˜ํƒ€๋‚ฌ๋‹ค..๐Ÿ˜ญ

์—๋Ÿฌ์˜ ํ‚ค์›Œ๋“œ๋Š” 'Parsing error: The keyword 'import' is reserved eslint' ๐Ÿ”ฅ

8-2. eslint ์—๋Ÿฌ

.eslintrc ํŒŒ์ผ์— "parser": "babel-eslint" ํ•œ ์ค„ ์ถ”๊ฐ€ํ–ˆ๋”๋‹ˆ ์—๋Ÿฌ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค ๐Ÿ˜‡


๐Ÿคš๐Ÿป ๋ฐ‘์— ์ ํžŒ npm i babel-eslint --save-dev ๋Š” ์•ˆํ•ด์คฌ๋‹ค!



9. ์ตœ์ข… ์„ค์ • ์ฝ”๋“œ (์—๋Ÿฌํ•ด๊ฒฐ) ๐Ÿ˜‡

9-1. .eslintrc

{
  "plugins": ["prettier"],
  "extends": [
    "prettier",
    "prettier/@typescript-eslint"
  ],
  "parser": "babel-eslint"
}

9-2. .prettierrc

{
  "tabWidth": 2,
  "endOfLine": "lf",
  "arrowParens": "avoid",
  "singleQuote": true,
  "semi": true,
  "trailingComma": "all",
  "printWidth": 80
}

9-3. setting.json (.vscodeํด๋”)

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "javascript.format.enable": false,
  "prettier.eslintIntegration": true,
  "prettier.disableLanguages": ["js"],
  "eslint.alwaysShowStatus": true,
  "files.autoSave": "onFocusChange"
}

9-4. ์ถฉ๋Œ ๋น„ํ™œ์„ฑํ™” ๋ช…๋ น

prettier ์„ค์ •๊ณผ ์ถฉ๋Œ๋˜๋Š” eslint ๊ทœ์น™์„ ๋น„ํ™œ์„ฑํ™”ํ•ด์ฃผ๋Š” ๋ช…๋ น

$ npm install --save-dev eslint-config-prettier


โœจ ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜๋ฉด์„œ ๋„์›€๋ฐ›์€ ๊ณณ

profile
Becoming a front-end developer ๐ŸŒฑ

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

comment-user-thumbnail
2021๋…„ 2์›” 16์ผ

์šฐ๋ฆฌ PM๋‹˜ ์—†์œผ๋ฉด ๋ชป์‚ด์•„ ํ™”์ดํŒ…๐ŸŒฑ

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ
comment-user-thumbnail
2021๋…„ 3์›” 2์ผ

๊ฐ“์†”๋‹˜.. ์ง„์งœ ํ›„์›ํ•˜๊ณ  ์‹ถ์€ ํŽ˜์ด์ง€๋„ค์š”!

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ