Skip to content

Commit

Permalink
chore: update docs (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost authored Oct 31, 2023
1 parent c4e7df9 commit a9e36be
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/config/farm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,42 @@ export function hmrPlugin(devServer: DevServer) {

Then configure the plugin into `server.plugins`.


## Environment variable

`Farm` distinguishes between development and production environments through `Farm` process.env.NODE_ ENV`.

In different environments, environment variables are replaced statically, so use static constants to represent environment variables instead of dynamic expressions.

### `.env` file

`Farm` uses `dotenv` to load your additional environment variables, such as `.env` files.

```js
// .env
FARM_APP_SECRET=secret
Farm_APP_PASSWORD=password
APP_VERSION=1.0.0
```

`Farm` loads the file `.env` via dotenv, and loads it into `process.env` and finally injects it into define.

:::warning
In order to ensure the security of the client, preventing the environment variables in the current system from being exposed to the client `Farm` will only identify some important environment variables that start with `Farm`.
:::

`Farm` expands environment variables through dotenv-expand


If you want to customize the prefix of env variables, you can configure `envPrefix`.

### envPrefix

* **default value**: `FARM_`

Customize the prefix of the `env` variable by configuring `envPrefix`.


## Plugins Options
Configure Farm's plug-ins, support Rust plug-ins or Js plug-ins, examples are as follows:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,44 @@ export function hmrPlugin(devServer: DevServer) {
然后将该插件配置到 `server.plugins` 中。


## Environment variable 环境变量

`Farm` 通过 `process.env.NODE_ENV` 来区分开发和生产环境。

在不同环境中, 环境变量会被静态替换, 所以请使用静态的常量来表示环境变量, 而不是动态的表达式.

### `.env` 文件

`Farm` 使用 `dotenv` 来加载您的额外的环境变量, 例如 `.env` 文件.

```js
// .env
FARM_APP_SECRET=secret
Farm_APP_PASSWORD=password
APP_VERSION=1.0.0
```

`Farm` 会通过 dotenv 加载 `.env` 文件, 并且将其加载到 `process.env` 中 最终在 define 中注入.

:::warning
为了保证客户端安全, 防止将当前系统中的环境变量暴露给客户端 `Farm` 只会识别以 `FARM_` 开头和一些重要的环境变量.
:::

`Farm` 通过 dotenv-expand 来拓展环境变量


如果你想自定义 env 变量的前缀,可以配置 `envPrefix`。

### envPrefix env 变量前缀

* **默认值**: `FARM_`

通过配置 `envPrefix` 来自定义 `env` 变量的前缀。

```ts



## Plugins Options
配置 Farm 的插件,支持 Rust 插件或者 Js 插件,示例如下:

Expand Down

0 comments on commit a9e36be

Please sign in to comment.