Frontend ๐Ÿ“š/React

[ ์ฝ”๋”ฉ์• ํ”Œ ] React ๋ฆฌ์•กํŠธ ๊ธฐ์ดˆ Part5

leejaejae 2023. 10. 14. 18:26

โœ๏ธ ๋งŒ๋“  React ์‚ฌ์ดํŠธ build & Github Pages๋กœ ๋ฐฐํฌ

0. ๋ฐฐํฌํ•˜๊ธฐ ์ „ ์ฒดํฌํ•  ์‚ฌํ•ญ
(1) ์ผ๋‹จ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋„์›Œ๋ณผ ๋•Œ ์ฝ˜์†”์ฐฝ, ํ„ฐ๋ฏธ๋„์— ์—๋Ÿฌ๊ฐ€ ๋‚˜๋ฉด ์•ˆ๋œ๋‹ค
(2) ํ˜น์‹œ ์‚ฌ์ดํŠธ๋ฅผ ๋ฐฐํฌํ•  ๋•Œ
http://codingapple.com/ ์—ฌ๊ธฐ์— ๋ฐฐํฌํ•˜๋Š” ๊ฒฝ์šฐ์—” ๋”ฐ๋กœ ์„ค์ •์ด ํ•„์š”์—†์ด ๋Œ€์ถฉ ํ•ด๋„ ๋˜์ง€๋งŒ http://codingapple.com/blog/ ์ด๋Ÿฐ ํ•˜์œ„ ๊ฒฝ๋กœ๋กœ ๋ฐฐํฌํ•˜๊ณ  ์‹ถ์œผ๋ฉด ํ”„๋กœ์ ํŠธ์— ์„ค์ •์ด ๋”ฐ๋กœ ํ•„์š”ํ•˜๋‹ค.

ํ”„๋กœ์ ํŠธ ํŒŒ์ผ ์ค‘ package.json ์ด๋ผ๋Š” ํŒŒ์ผ์„ ์˜คํ”ˆํ•ด 

"homepage": "http://codingapple.com/blog",

homepage๋ผ๋Š” ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€ํ•œ ํ›„, ๋ฐฐํฌํ•  ์‚ฌ์ดํŠธ ๊ฒฝ๋กœ๋ฅผ ๋’ค์— ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค. (ํ˜น์€ /blog ์ด๋ ‡๊ฒŒ ๊ฒฝ๋กœ๋ฅผ ์จ๋„ ๋จ)
๊ทธ๋ฆฌ๊ณ  ๋ฆฌ์•กํŠธ ๋ผ์šฐํ„ฐ๊ฐ€ ์„คํ”ผ๋˜์–ด ์žˆ๋‹ค๋ฉด ๋ผ์šฐํ„ฐ๊ฐ€ ์ œ๊ณตํ•˜๋Š” basename="" ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒŒ ๋ผ์šฐํŒ…์ด ์ž˜ ๋จ!
- ์ž์„ธํ•œ ๋‚ด์šฉ: https://create-react-app.dev/docs/deployment/#building-for-relative-paths

 

Deployment | Create React App

npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main..js are served with the contents of the /st

create-react-app.dev

 

1. ๋ณ„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋ฉด ์ด์ œ ํ„ฐ๋ฏธ๋„์— build ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅ
- state, JSX, <์ปดํฌ๋„ŒํŠธ>, props ์ด๋Ÿฐ ๋ฌธ๋ฒ•๋“ค์€ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ํ•ด์„ํ•  ์ˆ˜ ์—†์–ด ๊ทธ๋Œ€๋กœ ๋ฐฐํฌํ•  ์ˆ˜ ์—†๋‹ค.
- ๋”ฐ๋ผ์„œ ์ด๋Ÿฌํ•œ ๋ฌธ๋ฒ•๋“ค์„ CSS, JS, HTML ๋ฌธ๋ฒ•์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค.( ์ด๊ฒƒ์„ ์ปดํŒŒ์ผ ๋˜๋Š” build ๋ผ๊ณ  ํ•œ๋‹ค. ) 
- build ํ•˜๋ ค๋ฉด ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ์—์„œ ํ„ฐ๋ฏธ๋„์„ ์ผ  ํ›„ ์•„๋ž˜ ์ž…๋ ฅ

npm run build

- ๊ทธ๋Ÿผ ์ž‘์—… ํ”„๋กœ์ ํŠธ ํด๋” ๋‚ด์— build ๋ผ๋Š” ํด๋”๊ฐ€ ํ•˜๋‚˜ ์ƒ์„ฑ๋˜๋Š”๋ฐ ์•ž์„œ ์งฐ๋˜ ์ฝ”๋“œ๋ฅผ ์ „๋ถ€ .html, .css, .jsํŒŒ์ผ๋กœ ๋ณ€ํ™˜ํ•ด์„œ ๊ฑฐ๊ธฐ ๋‹ด์•„์คŒ!
- build ํด๋” ์•ˆ์— ์žˆ๋Š” ๋‚ด์šฉ์„ ๋ชจ๋‘ ์„œ๋ฒ„์— ์˜ฌ๋ฆฌ๋ฉด ๋! (index.html์ด ๋ฉ”์ธ ํŽ˜์ด์ง€)

 

2. ๊ทผ๋ฐ ์šฐ๋ฆฐ ๋ฌด๋ฃŒ ํ˜ธ์ŠคํŒ…ํ•ด์ฃผ๋Š” github pages์— ์˜ฌ๋ฆด ๊ฒƒ
(1) guthub.com ๋กœ๊ทธ์ธ
(2) ์šฐ์ธก ์ƒ๋‹จ + ๋ฒ„ํŠผ ๋ˆ„๋ฅด๊ณ  New Repository ์ƒ์„ฑ
(3) Repository name์€ ๊ผญ ์™ผ์ชฝ์— ๋œจ๋Š” ๋ณธ์ธ์•„์ด๋””.github.io ๋ผ๊ณ  ์ž…๋ ฅ, READM ํŒŒ์ผ ์ƒ์„ฑ๋„ ์ฒดํฌ

 

3. Repository์— html ํŒŒ์ผ ์˜ฌ๋ฆฌ๊ธฐ
- repository์— build ํด๋” ๋‚ด์˜ ํŒŒ์ผ์„ ์ „๋ถ€ ๋“œ๋ž˜๊ทธ ์•ค ๋“œ๋กญ
- ์ฃผ์˜! build ํด๋”๋ฅผ ๋“œ๋ž˜๊ทธ ์•ค ๋“œ๋กญ ์•„๋‹˜, build ํด๋” ์•ˆ์˜ ๋‚ด์šฉ๋ฌผ์„!

 

Q. build ํ•  ๋•Œ ์••์ถ• ์‹œํ‚ค์ง€ ๋ง๊ณ  ๋‚จ๊ธฐ๋กœ ์‹ถ์€ ํŒŒ์ผ์€?
./ ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ๋กœ๋กœ ์ฒจ๋ถ€ํ•œ ์ด๋ฏธ์ง€, .js ํŒŒ์ผ๋“ค์€ ์ „๋ถ€ ์ด๋ฆ„์€ ๋ณ€ํ•œ๋‹ค. ์ด๋ฆ„์ด ๋ณ€ํ•˜์ง€ ์•Š๊ฒŒ ํ•˜๊ณ  ์‹ถ์œผ๋ฉด public ํŒŒ์ผ ์•ˆ์— ๋„ฃ๊ณ  build.


๋ณธ ํฌ์ŠคํŒ…์€ << React ๋ฆฌ์•กํŠธ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‡ผํ•‘๋ชฐ ํ”„๋กœ์ ํŠธ๊นŒ์ง€! >> ๊ฐ•์˜๋ฅผ ์ฐธ๊ณ ํ•ฉ๋‹ˆ๋‹ค.