Environment Variables

Eunji ParkΒ·2022λ…„ 7μ›” 20일
0

Next.js | μ½”λ”©μ•™λ§ˆ

λͺ©λ‘ 보기
10/13
post-thumbnail

βœ“ ν™˜κ²½ λ³€μˆ˜ ( Environment Variables )

ν™˜κ²½ λ³€μˆ˜ κ΅¬λΆ„μ΄λž€ ν™˜κ²½μ— 따라 λ³€ν•  수 μžˆλŠ” 값듀을 λΆ„κΈ° μ²˜λ¦¬ν•˜λŠ” μž‘μ—…μ„ λ§ν•œλ‹€.

예λ₯Ό λ“€λ©΄,
β€’ Development ν™˜κ²½μ—μ„œλŠ” A λ¦¬μŠ€νŠΈμ΄μ§€λ§Œ, μ‹€μ œ Production ν™˜κ²½μ—μ„œλŠ” B λ¦¬μŠ€νŠΈκ°€ λ‚˜μ™€μ•Ό ν•˜λŠ” 경우
β€’ ν…ŒμŠ€νŠΈ 데이터와 μ‹€μ œ μ„œλΉ„μŠ€ 데이터가 κ΅¬λΆ„λ˜λŠ” 경우
등이 μžˆλ‹€.

Next.js λŠ” 별닀λ₯Έ μž‘μ—… 없이 ν™˜κ²½λ³€μˆ˜λ₯Ό μ‚¬μš©ν•  수 μžˆλ„λ‘ μ œκ³΅ν•œλ‹€.



πŸ“– μ‚¬μš©λ²•

πŸ”” Notice
μ‚¬μš©λ²•μ€ Node.js ν™˜κ²½κ³Ό Browser ν™˜κ²½μ΄ λ‹€λ₯΄λ―€λ‘œ μ£Όμ˜ν•œλ‹€!
β€’ Node.js : Β process.env.λ³€μˆ˜λͺ…
β€’ Browser : Β process.env.NEXT_PUBLIC_λ³€μˆ˜λͺ…

.env.development

πŸ“ / .env.development

.env.production

πŸ“ / .env.production

πŸ”” Notice
name 은 Node.js ν™˜κ²½μ—μ„œ μ‚¬μš©ν•΄λ³΄κ³ ,
μ•žμ— NEXT_PUBLIC_ 이 뢙은 λ³€μˆ˜λŠ” Browser ν™˜κ²½μ—μ„œ μ‚¬μš©ν•΄λ³΄μž.

index.js

πŸ“ / pages / index.js

[id].js

πŸ“ / pages / view / [id].js




βœ“ κ²°κ³Ό 확인

Development Mode

npm run dev 둜 개발 ν™˜κ²½μ—μ„œ κ²°κ³Όλ₯Ό ν™•μΈν•΄λ³΄μž.

home λ©”λ‰΄μ—μ„œλŠ” Maybelline λΈŒλžœλ“œμ˜ μ œν’ˆ λ¦¬μŠ€νŠΈκ°€ λ‚˜νƒ€λ‚˜κ³ ,
μƒμ„ΈνŽ˜μ΄μ§€μ—μ„œλŠ” "DEVELOPMENT ν™˜κ²½μž…λ‹ˆλ‹€." λΌλŠ” λ©”μ‹œμ§€κ°€ λ‚˜νƒ€λ‚œλ‹€.

Production Mode

npm run build & npm run start둜 ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œ κ²°κ³Όλ₯Ό ν™•μΈν•΄λ³΄μž.

home λ©”λ‰΄μ—μ„œλŠ” Dior λΈŒλžœλ“œμ˜ μ œν’ˆ λ¦¬μŠ€νŠΈκ°€ λ‚˜νƒ€λ‚˜κ³ ,
μƒμ„ΈνŽ˜μ΄μ§€μ—μ„œλŠ” "PRODUCTION ν™˜κ²½μž…λ‹ˆλ‹€." λΌλŠ” λ©”μ‹œμ§€κ°€ λ‚˜νƒ€λ‚œλ‹€.

0개의 λŒ“κΈ€