๊ฐœ์š” ๐Ÿ“ฃ

๋กœ์ปฌ ์„œ๋ฒ„์—์„œ ๊ฐœ๋ฐœํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ,
ํ˜ธ์ŠคํŒ…์„ ํ†ตํ•ด ๋„๋ฉ”์ธ์„ ์–ป์–ด ์™ธ๋ถ€์—์„œ์˜ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋ฐฐํฌ(Deploy)๋ผ๊ณ  ํ•œ๋‹ค.
๋Œ€ํ‘œ์ ์ธ ํ˜ธ์ŠคํŒ… ์„œ๋น„์Šค๋กœ๋Š” Netlify, Vercel, AWS, Github Pages ๋“ฑ ์ด ์žˆ์ง€๋งŒ,
์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š”,
Google ์—์„œ ์ œ๊ณตํ•˜๋Š” Firebase ๋ฅผ ํ†ตํ•œ ํ˜ธ์ŠคํŒ… ์ฒ˜๋ฆฌ๋ฅผ ์ •๋ฆฌํ•˜๊ณ ์ž ํ•œ๋‹ค.


ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ๐ŸŽ‰

Firebase ์›น ํ˜ธ์ŠคํŒ… ์ƒ์„ฑ ๋ฐ ๋ฐฐํฌํ•˜๊ธฐ ์ž‘์—… ์ˆœ์„œ๋Š” ํฌ๊ฒŒ ์•„๋ž˜์™€ ๊ฐ™์ด ์ง„ํ–‰๋œ๋‹ค.

1๏ธโƒฃ Firebase ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
2๏ธโƒฃ Firebase ํ˜ธ์ŠคํŒ… ์„ค์ •
3๏ธโƒฃ Firebase ์ดˆ๊ธฐํ™”
4๏ธโƒฃ Firebase ๋ฐฐํฌ ๋ฐ ํ™•์ธ

https://console.firebase.google.com/

๋จผ์ € ํ•ด๋‹น URL ์—์„œ ์ƒˆ๋กœ์šด Firebase ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑ ํ•ด ์ค€๋‹ค.


install ๐Ÿ”ฎ

์šฐ๋ฆฌ๋Š” ์›น ์•ฑ์„ ๋ฐฐํฌํ•˜๋ ค๊ณ  ํ•˜๋‹ˆ,
์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ์˜ ํ”„๋กœ์ ํŠธ ๊ฐœ์š” ํ™”๋ฉด์—์„œ ์›น ๋ฒ„ํŠผ์„ ํด๋ฆญ ํ•ด ์ค€๋‹ค.

์•ฑ ๋‹‰๋„ค์ž„์„ ์„ค์ • ํ•ด ์ค€๋’ค ํ˜ธ์ŠคํŒ… ์ฒดํฌ๋ฐ•์Šค๋„ ์ฒดํฌ ํ•ด ์ค€๋‹ค.

npm ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ์—์„œ firebase ๋ชจ๋“ˆ์„ ์„ค์น˜ ํ•ด ์ค€๋‹ค.

npm install firebase
yarn add firebase

firebase SDK ๋Š” ์ถ”ํ›„ ๋ชจ๋“ˆ์„ ์ดˆ๊ธฐํ™” ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋ฏ€๋กœ ํด๋ฆฝ๋ณด๋“œ์— ์ €์žฅ ํ•ด ๋†“์ž

๋‹ค์Œ์œผ๋กœ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด
Firebase ๋กœ ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ ๊ด€๋ฆฌ, ๋ฐฐํฌ, DB ๊ด€๋ฆฌ ๋“ฑ ์„ ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“ˆ์„ ์ „์—ญ์œผ๋กœ ์„ค์น˜ ํ•ด ์ค€๋‹ค.

npm install -g firebase-tools
yarn global add firebase-tools

init ๐Ÿ’พ

ํ”„๋กœ์ ํŠธ ํ„ฐ๋ฏธ๋„์— firebase login ์„ ์‹คํ–‰ํ•˜์—ฌ,
ํ”„๋กœ์ ํŠธ์™€ ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ์—ฐ๊ฒฐํ•  ์ค€๋น„๋ฅผ ํ•œ๋‹ค.

ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด, ์ƒˆ ์ฐฝ์œผ๋กœ google ๋กœ๊ทธ์ธ ํ™”๋ฉด์ด ์‹คํ–‰๋œ๋‹ค.

  • ์ด๋ฏธ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋กœ๊ทธ์ธ ๋œ ์ƒํƒœ

๋งŒ์•ฝ Local ์— ์—ฐ๊ฒฐ๋œ ๊ตฌ๊ธ€ ๊ณ„์ •์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด
firebase logout ๋ช…๋ น์œผ๋กœ ์—ฐ๊ฒฐ์„ ๋Š์–ด์ค˜์•ผ ํ•œ๋‹ค.


firebase init

ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Hosting: Configue files for Firebase Hosting โ€ฆ ์„
์ŠคํŽ˜์ด์Šค ๋ฐ” ๋ฅผ ๋ˆŒ๋Ÿฌ ์„ ํƒ ํ›„ Enter

์•ž์„œ ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ์„ ํƒ ํ•ด ์ค€๋‹ค. Select a default Firebase project for this directory:

Vite ๋กœ ์ƒ์„ฑํ•œ ์•ฑ์ผ ๊ฒฝ์šฐ npm run build ํ˜น์€ yarn run build ๋ช…๋ น์„ ์‹คํ–‰ ์‹œ
dist ํด๋”๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.
(React ์˜ ๊ฒฝ์šฐ build ํด๋” ์ƒ์„ฑ)

Are you ready to proceed? (Y/N)
๐Ÿ‘‰ ์ง„ํ–‰์—ฌ๋ถ€ Y

What do you want to use as your public directory?
๐Ÿ‘‰ dist ๋ผ๊ณ  ์ ์–ด์ค€๋‹ค
(npm run build ๋กœ ๋‚˜์˜จ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—)

Configure as a single-page app (rewrite all urls to /index.html)? (Y/N)
๐Ÿ‘‰ SPA ์ผ๊ฒฝ์šฐ index.html ์„ ๊ธฐ๋ณธ์œผ๋กœ ๋ณด์—ฌ์ฃผ๊ฒ ๋‹ค๋Š” ์—ฌ๋ถ€ Y
(๋ฆฌ์•กํŠธ์ด๊ธฐ ๋•Œ๋ฌธ์— SPA)

Set up automatic builds and deploys with GitHub? (Y/N)
๐Ÿ‘‰ GitHub๋กœ ์ž๋™ ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌ ์„ค์ • N

File build/index.html already exists. Overwrite? (Y/N)
๐Ÿ‘‰ ์ด๋ฏธ ์ƒ์„ฑ๋œ index.html์„ ๋ฎ์–ด์“ฐ๋Š”์—ฌ๋ถ€ N
(๋ฎ์–ด์“ฐ๋ฉด ๋ฆฌ์•กํŠธ๋กœ build ๋œ ํŒŒ์ผ์ด ์ดˆ๊ธฐํ™”๋˜๊ธฐ ๋•Œ๋ฌธ์— N)

init ์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด Hosting ์„ ํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ์ผ๊ณผ ํด๋”๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.


build ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ  firebase deploy ๋ช…๋ น์–ด๋งŒ์„ ์‹คํ–‰ํ•˜๋ฉด,
๋ฐฐํฌ๊ฐ€ ์ง„ํ–‰๋˜๋ฉฐ ์ƒ์„ฑ๋œ Hosting URL ์ฃผ์†Œ๋กœ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ƒ์„ฑ๋œ ํ˜ธ์ŠคํŒ… ์ฃผ์†Œ๋กœ ์ ‘์† ์‹œ ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ์ถœ๋ ฅ๋œ๋‹ค๋ฉด,
ํ˜ธ์ŠคํŒ…(๋ฐฐํฌ) ์— ์„ฑ๊ณต ํ•œ ๊ฒƒ์ด๋‹ค.

์ž‘์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ๋ฐ˜์˜์‹œํ‚ค๋ ค๋ฉด,
build ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๋‹ค์‹œ firebase deploy ๋ช…๋ น์œผ๋กœ ์ ์šฉ์‹œํ‚ค๋ฉด ๋œ๋‹ค.


Error โŒ

๋งŒ์•ฝ 404 ์—๋Ÿฌ Page Not Fount ๊ฐ€ ๋œฌ๋‹ค๋ฉด,
firebase.json ํŒŒ์ผ์„ ์ˆ˜์ • ํ•ด ์ค€๋‹ค.

{
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

๋ฐฐํฌ ํ™•์ธ โœ”๏ธ

๋„๋ฉ”์ธ๊ณผ ํ•จ๊ป˜ ์„ฑ๊ณต์ ์œผ๋กœ Deploy ๋œ ์ƒํƒœ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.


Reference ๐ŸŒŠ

https://wavescats.github.io/react/2022/10/21/react18.html
https://firebase.google.com/docs/hosting?hl=ko
https://firebase.google.com/docs/hosting/quickstart?hl=ko
https://lxxyeon.tistory.com/38
https://velog.io/@hippohami/Firebase-%EC%9B%B9-%ED%98%B8%EC%8A%A4%ED%8C%85-%EC%84%A4%EC%A0%95-%EB%B0%B0%ED%8F%AC-%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95