๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
React

[๋ฆฌ์•กํŠธ ์„ธํŒ…-1]Typescript + React + Express.js ํ”„๋ ˆ์ž„์›Œํฌ + Prettiers ํ™˜๊ฒฝ ์„ธํŒ…ํ•˜๊ธฐ

by devebucks 2021. 6. 2.
728x90

๐Ÿ“ ๋ชฉ์ฐจ

1. Typescript + React ์„ธํŒ…โš™ 

2. babel ์„ธํŒ… ๋ฐ Express.js ํ”„๋ ˆ์ž„์›Œํฌ ์„ธํŒ…โš™ 

 

๐Ÿ“ฆ ์šด์˜ํ™˜๊ฒฝ ๊ณ ๋ ค

๋ฐฐํฌ๋ฅผ ์ƒ๊ฐํ•˜๋ฉด, ํ”„๋กœ์ ํŠธ๋ฅผ ๋”ฐ๋กœ ๋งŒ๋“œ๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์„œ๋ฒ„์™€ ์›น ๋ณ„๋„๋กœ repo๋ฅผ ์ƒ์„ฑํ•ด์„œ ์„œ๋ฒ„์™€ ์›น ์ฝ”๋“œ๋ฅผ ๋ถ„๋ฆฌํ•ด์„œ ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋‚˜๋ˆ ์„œ ์ฝ”๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉด ์ข‹์€ ์ ์ด ๋ฐฐํฌํ•  ๋•Œ, ์„œ๋ฒ„์™€ ์›น์„ ๋ณ„๋„๋กœ ๋ฐฐํฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

 

๋กœ์ปฌ์—๋Š” ํ•˜๋‚˜์˜ ํด๋”์— ๋‘ ๊ฐœ์˜ repo๋ฅผ ๋„ฃ์–ด์„œ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ
ใ„ด front-end
ใ„ด back-end

 

 

 

โš™ Typescript + React ์„ธํŒ…

๋กœ์ปฌ์— ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•  ๋•Œ๋Š” ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

npx create-react-app --template typescript ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ 

yarn create react-app --template typescript ํ”„๋กœ์ ํŠธ ์ด๋ฆ„

ํ”„๋กœ์ ํŠธ ํด๋”๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ, ํ”„๋กœ์ ํŠธ ํด๋”์˜ ํ™ˆ ๊ฒฝ๋กœ์—์„œ ๋ช…๋ น์–ด๋ฅผ ํ„ฐ๋ฏธ๋„์— ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

npx create-react-app --template typescript .

์„ค์น˜๊ฐ€ ๋๋‚˜๋ฉด, ํ”„๋กœ์ ํŠธ ํŒŒ์ผ์ด ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

package.jsonํŒŒ์ผ์— script ๊ฐ์ฒด๋ฅผ ๋ณด๋ฉด, start ํ‚ค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

ํ”„๋กœ์ ํŠธ ํ™ˆ ๊ฒฝ๋กœ ํ„ฐ๋ฏธ๋„์—์„œ npm start๋กœ ์•ฑ์„ ์‹คํ–‰์‹œ์ผœ ๋ด…์‹œ๋‹ค.

 

์‹คํ–‰ ํ™”๋ฉด

๋„ค. ์˜ˆ์ฉ๋‹ˆ๋‹ค.

testing-library๊ฐ€ cra์— ์ž๋™์œผ๋กœ ์„ค์น˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. redux์™€ redux-saga๋ฅผ ์„ค์น˜ํ•ด์„œ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•ด๋ด…์‹œ๋‹ค.

 

Redux & Redux-saga ์„ค์น˜

 

 

 

 

โš™ Express.js ํ”„๋ ˆ์ž„์›Œํฌ ์„ธํŒ…

 

1. back-end ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  node ์ดˆ๊ธฐํ™”๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

$ npm init -y

 

2. Babel ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.  Oh my  babel ์ฐธ๊ณ ํ•˜๊ธฐ

$ npm i -D babel-cli
$ npm i -D babel-preset-es2015

.Babelrc ์„ค์ •ํ•˜๊ณ , ์‹คํ–‰ ์‹œ, ๋นŒ๋“œํ•˜๊ณ  ์‹คํ–‰๋˜๋„๋ก package.json ์„ค์ •์„ ํ•ด์ค๋‹ˆ๋‹ค. -> ํ™•์ธํ•˜๊ธฐ

 

3. express๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

$ npm i express

 

server.js ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

const express = require('express');
const app = express();
const port = process.env.port || 3001;

app.use(bodyParser.json());
app.use('/api', (req, res) => res.json({ name: "์„ ๋ฆ‰์—ญ"}));

express.listen();

 

package.json ์„ค์ •

script๊ฐ์ฒด์— 

"start":"node ./server.js"

 

์‹คํ–‰

$ npm run start

 

โš™ nodemon์œผ๋กœ node ์„œ๋ฒ„ ๊ฐœ๋ฐœํ™˜๊ฒฝ ์ž๋™ํ™”ํ•˜๊ธฐ

Prettierrc ์„ธํŒ…

์ด์ œ Prettierrc๋ฅผ ์„ค์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

vscode plugin์œผ๋กœ prettierrc๋ฅผ ๋‹ค์šด๋ฐ›์Šต๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ํ™ˆ ๊ฒฝ๋กœ์— .prettierrc ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.  ๊ทธ๋ฆฌ๊ณ , ๋‚ด์šฉ์œผ๋กœ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋„ฃ์Šต๋‹ˆ๋‹ค.

{
  "printWidth": 200,
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": true,
  "singleQuote": true
}

 

728x90

๋Œ“๊ธ€