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: update env-variables.md #12165

Merged
merged 4 commits into from
Mar 2, 2024
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
21 changes: 21 additions & 0 deletions docs/docs/docs/guides/env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,31 @@ BAR=bar
CONCAT=$FOO$BAR # CONCAT=foobar
```

通过 `.env.development` / `.env.production` 来为开发和构建分别配置不同的环境变量。

注意:

* 不建议将 `.env.local` 加入版本管理中。

### 在浏览器中使用环境变量

所有通过 `.env` 环境变量文件 或 命令行注入 的环境变量均默认只在 Umi 配置文件 (Node.js 环境) 内生效,在浏览器中无法直接通过 `process.env.VAR_NAME` 方式使用,通过进一步配置 [`define`](../api/config.md#define) 来注入到浏览器环境中:

```bash
# .env
MY_TOKEN="xxxxx"
```

fz6m marked this conversation as resolved.
Show resolved Hide resolved
<br />

```ts
// .umirc.ts

define: { 'process.env.MY_TOKEN': process.env.MY_TOKEN }
```

注:我们约定所有以 `UMI_APP_` 开头的环境变量会默认注入到浏览器中,无需配置 `define` 手动注入。

## 环境变量列表

按字母顺序排列。
Expand Down
Loading