Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: 실험적 원시 환경 변수 값
sidebar:
label: 원시 환경 변수
i18nReady: true
---

import Since from '~/components/Since.astro'

<p>

**타입:** `boolean`<br />
**기본값:** `false`<br />
<Since v="5.12.0" />
</p>

Astro를 사용하면 [환경 변수에 대한 타입 안전 스키마](/ko/guides/environment-variables/#타입-안전-환경-변수)를 구성할 수 있으며, `astro:env`를 통해 가져온 변수를 예상 타입으로 변환할 수 있습니다.

그러나 Astro는 경우에 따라 `import.meta.env`를 통해 사용되는 환경 변수도 변환하므로 문자열 `"true"` (부울 값으로 변환) 및 `"1"` (숫자로 변환)과 같은 일부 값에 액세스하지 못할 수도 있습니다.

`experimental.rawEnvValues` 플래그를 사용하면 `process.env`에서 채워지는 `import.meta.env` 값의 강제 변환을 비활성화하여 원시 값을 사용할 수 있습니다.

Astro가 `import.meta.env`를 통해 사용되는 값을 강제로 변환하지 못하게 하려면 Astro 구성에서 `experimental.rawEnvValues` 플래그를 `true`로 설정하세요.

```js title="astro.config.mjs" ins={4-6}
import { defineConfig } from "astro/config"

export default defineConfig({
experimental: {
rawEnvValues: true,
}
})
```

## 사용

이 실험적 플래그를 활성화하면 더 이상 문자열 값을 부울이나 숫자로 변환하지 않습니다. 이렇게 하면 Astro에서 `import.meta.env`의 동작이 [Vite](https://ko.vite.dev/guide/env-and-mode#env-variables)와 일치하게 됩니다.

향후 주요 버전에서 Astro가 기본적으로 `import.meta.env` 값을 강제로 변환하지 않도록 전환할 예정이지만, `experimental.rawEnvValues` 플래그를 사용하여 향후 동작을 미리 선택하고 필요한 경우 그에 따라 [프로젝트를 업데이트](#프로젝트-업데이트)할 수 있습니다.

### 프로젝트 업데이트

이 강제 변환에 의존하고 있다면 프로젝트 코드를 업데이트하여 수동으로 적용해야 할 수도 있습니다.

```ts title="src/components/MyComponent.astro" del={1} ins={2}
const enabled: boolean = import.meta.env.ENABLED
const enabled: boolean = import.meta.env.ENABLED === "true"
```

Astro에서 강제 변환이 필요한 경우 [`astro:env`](/ko/guides/environment-variables/)를 사용하는 것이 좋습니다.