Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 03-pages > 02-api-reference > 03-next-config-js > env.mdx (수정) #418

Merged
merged 4 commits into from
Jul 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions docs/03-pages/02-api-reference/03-next-config-js/env.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,3 @@
title: 환경 변수
description: 빌드 시 Next.js 애플리케이션에서 환경 변수를 추가하고 액세스하는 방법을 알아보세요.
---
Copy link
Contributor

@chaejunlee chaejunlee Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
---
source: app/api-reference/next-config-js/env
---

source 부분 추가해주세요! pages 문서는 app 문서 내용을 바라보기 때문에 source 빼먹으시면 안 됩니다.


Copy link
Contributor

@chaejunlee chaejunlee Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PageOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}

아래 내용 추가해주세요! 주석 부분도 지우시면 안 됩니다.

> [Next.js 9.4](https://nextjs.org/blog/next-9-4)의 출시 이후로 [환경 변수 추가하기](/docs/pages/building-your-application/configuring/environment-variables)가 더 직관적이고 사용하기 쉽습니다. 한번 시도해 보세요!

<details>
<summary>예제</summary>

- [env 활용하기](https://github.com/vercel/next.js/tree/canary/examples/with-env-from-next-config-js)

</details>

> **참고**. 이런 방식으로 지정된 환경 변수들은 **항상** 자바스크립트 번들에 포함됩니다. 환경 변수 이름 앞에 `NEXT_PUBLIC_`를 붙이는 것은 환경 변수들을 [환경 또는 .env 파일을 통해](/docs/pages/building-your-application/configuring/environment-variables) 지정할 때만 효과가 있습니다.

자바스크립트 번들에 환경 변수를 추가하려면 `next.config.js`를 열고 `env` 설정을 추가하세요.

```js filename="next.config.js"
module.exports = {
env: {
customKey: 'my-value',
},
}
```

이제 코드에서 `process.env.customKey`에 접근할 수 있습니다. 예시를 보세요.

```jsx
function Page() {
return <h1>The value of customKey is: {process.env.customKey}</h1>
}

export default Page
```

Next.js는 빌드 시에 `process.env.customKey`를 `'my-value'`로 대체할 것입니다. 웹팩 [DefinePlugin](https://webpack.js.org/plugins/define-plugin/)의 특성 때문에 `process.env` 변수는 구조 분해할 수 없습니다.

예를 들어 다음과 같은 줄은,

```jsx
return <h1>The value of customKey is: {process.env.customKey}</h1>
```

아래와 같이 변환될 것입니다.

```jsx
return <h1>The value of customKey is: {'my-value'}</h1>
```