Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Nov 16, 2024
1 parent 36af255 commit ebf778b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions website/docs/en/guide/advanced/env-vars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ During code minification, `if (false) { ... }` will be recognized as invalid cod
## `.env` File
When a `.env` file exists in the project root directory, Rsbuild CLI will automatically use [dotenv](https://npmjs.com/package/dotenv) to load these env variables and add them to the current Node.js process, The [Public Variables](#public-variables) will be exposed in the client code.
When a `.env` file exists in the project root directory, Rsbuild CLI will automatically use [dotenv](https://npmjs.com/package/dotenv) to load these env variables and add them to the current Node.js process. The [Public Variables](#public-variables) will be exposed in the client code.
You can access these env variables through `import.meta.env.[name]` or `process.env.[name]`.
Expand Down Expand Up @@ -280,7 +280,7 @@ If you are not using the Rsbuild CLI and are using the Rsbuild [JavaScript API](
```ts
import { loadEnv, mergeRsbuildConfig } from '@rsbuild/core';
// Here publicVars is the PUBLIC_ prefixed variable read by default.
// By default, `publicVars` are variables prefixed with `PUBLIC_`
const { parsed, publicVars } = loadEnv();
const mergedConfig = mergeRsbuildConfig(
Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/guide/advanced/env-vars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ if (false) {
## `.env` 文件
当项目根目录存在 `.env` 文件时,Rsbuild CLI 会自动使用 [dotenv](https://npmjs.com/package/dotenv) 来加载这些环境变量,并添加到当前 Node.js 进程中,其中的 [public 变量](#public-变量) 会被暴露在`client`代码中。
当项目根目录存在 `.env` 文件时,Rsbuild CLI 会自动使用 [dotenv](https://npmjs.com/package/dotenv) 来加载这些环境变量,并添加到当前 Node.js 进程中,其中的 [public 变量](#public-变量) 会被暴露在 `client` 代码中。
你可以通过 `import.meta.env.[name]``process.env.[name]` 来访问这些环境变量。
Expand Down Expand Up @@ -280,7 +280,7 @@ console.log(process.env.BAR); // '2'
```ts
import { loadEnv, mergeRsbuildConfig } from '@rsbuild/core';
// 此处 publicVars 为默认方式读取的 PUBLIC_ 前缀的变量
// 默认情况下,`publicVars` 是以 `PUBLIC_` 为前缀的变量
const { parsed, publicVars } = loadEnv();
const mergedConfig = mergeRsbuildConfig(
Expand Down

0 comments on commit ebf778b

Please sign in to comment.