> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# Interface: Config

`Config` 是 `rspeedy` 使用的配置。

## Properties

### dev?

> `optional` **dev?**: [`Dev`](/next/zh/api/packages/rspeedy/interfaces/Dev.md)

[Dev](/next/zh/api/packages/rspeedy/interfaces/Dev.md) 选项用于控制与开发相关的行为，包括 HMR、DevServer 等。

#### Default Value

```ts
undefined
```

***

### environments?

> `optional` **environments?**: `Record`\<`string`, `EnvironmentConfig`>

**`Lynx Default Changed`**

[Config.environments](#environments) 选项用于设置输出的 environment。

#### Default Value

未设置该选项时，Rspeedy 会向 Rsbuild 传入 `{ lynx: {} }`。

#### Remarks

如果你没有使用 Lynx for Web，通常不需要此选项。

#### Examples

- 为 Lynx 和 Web 使用不同的入口。

```ts
import { defineConfig } from '@lynx-js/rspeedy'

export default defineConfig({
  environments: {
    lynx: {},
    web: {
      source: { entry: { web: './src/index.web.jsx' } },
    },
  },
  source: {
    entry: './src/index.jsx',
  },
})
```

- 仅构建 Web 产物。

```ts
import { defineConfig } from '@lynx-js/rspeedy'

export default defineConfig({
  environments: {
    web: {
      source: { entry: { web: './src/index.web.jsx' } },
    },
  },
})
```

***

### mode?

> `optional` **mode?**: `"none"` | `"development"` | `"production"`

指定 Rsbuild 和 Rspack 的构建模式，不同模式有不同的默认行为和优化。

#### Default Value

取决于 `process.env.NODE_ENV`：

- `NODE_ENV` 为 `'production'` 时为 `'production'`
- `NODE_ENV` 为 `'development'` 时为 `'development'`
- 其他情况为 `'none'`

使用 Rspeedy CLI 时，`rspeedy dev` 和 `rspeedy preview` 默认为 `'development'`，`rspeedy build` 默认为 `'production'`。

#### Examples

```ts
If the value of `mode` is `'development'`:

- Enable HMR and register the {@link https://rspack.rs/plugins/webpack/hot-module-replacement-plugin | HotModuleReplacementPlugin}.

- Generate JavaScript and CSS source maps. In Lynx environments, all `.map` assets are removed before emit. See {@link Output.sourceMap} for details.

- The `process.env.NODE_ENV` in the source code will be replaced with `'development'`.

- The `import.meta.env.MODE` in the source code will be replaced with `'development'`.

- The `import.meta.env.DEV` in the source code will be replaced with `true`.

- The `import.meta.env.PROD` in the source code will be replaced with `false`.
```

```ts
If the value of `mode` is `'production'`:

- Enable JavaScript code minification and register the {@link https://rspack.rs/plugins/rspack/swc-js-minimizer-rspack-plugin | SwcJsMinimizerRspackPlugin}.

- Generated JavaScript and CSS filenames will have hash suffixes, see {@link Output.filenameHash}.

- Generated CSS Modules classnames will be shorter, see {@link CssModules.localIdentName}.

- Generate JavaScript and CSS source maps. In Lynx environments, all `.map` assets are removed before emit. See {@link Output.sourceMap}.

- The `process.env.NODE_ENV` in the source code will be replaced with `'production'`.

- The `import.meta.env.MODE` in the source code will be replaced with `'production'`.

- The `import.meta.env.DEV` in the source code will be replaced with `false`.

- The `import.meta.env.PROD` in the source code will be replaced with `true`.
```

***

### output?

> `optional` **output?**: [`Output`](/next/zh/api/packages/rspeedy/interfaces/Output.md)

[Output](/next/zh/api/packages/rspeedy/interfaces/Output.md) 选项用于设置 bundle 和静态资源的输出方式与输出位置。

#### Default Value

```ts
undefined
```

***

### performance?

> `optional` **performance?**: [`Performance`](/next/zh/api/packages/rspeedy/interfaces/Performance.md)

[Performance](/next/zh/api/packages/rspeedy/interfaces/Performance.md) 选项用于优化构建时和运行时的性能。

#### Default Value

```ts
undefined
```

***

### plugins?

> `optional` **plugins?**: `RsbuildPlugins`

`plugins` 选项用于以多种方式自定义构建流程。

#### Default Value

```ts
undefined
```

#### Remarks

Rspeedy 使用 [Rsbuild](https://rsbuild.rs/plugins/dev/index) 的插件 API。开发插件请参阅相应文档。

***

### resolve?

> `optional` **resolve?**: [`Resolve`](/next/zh/api/packages/rspeedy/interfaces/Resolve.md)

[Resolve](/next/zh/api/packages/rspeedy/interfaces/Resolve.md) 选项用于控制 Rspack 的模块解析行为。

#### Default Value

```ts
undefined
```

***

### server?

> `optional` **server?**: [`Server`](/next/zh/api/packages/rspeedy/interfaces/Server.md)

[Server](/next/zh/api/packages/rspeedy/interfaces/Server.md) 选项用于改变 dev-server 的行为。

#### Default Value

```ts
undefined
```

***

### source?

> `optional` **source?**: [`Source`](/next/zh/api/packages/rspeedy/interfaces/Source.md)

[Source](/next/zh/api/packages/rspeedy/interfaces/Source.md) 选项用于修改源文件相关的行为。

#### Default Value

```ts
undefined
```

***

### splitChunks?

> `optional` **splitChunks?**: `false` | `SplitChunksConfig`

配置 chunk 拆分。

#### Default Value

Rspeedy 将其默认设为 `false`；如果配置了该项，Rsbuild 会通过其顶层的 `splitChunks` 选项来处理。

#### Remarks

详见 [Rsbuild - splitChunks](https://rsbuild.rs/config/split-chunks)。

***

### tools?

> `optional` **tools?**: [`Tools`](/next/zh/api/packages/rspeedy/interfaces/Tools.md)

[Tools](/next/zh/api/packages/rspeedy/interfaces/Tools.md) 选项用于修改各类构建工具的行为。

#### Default Value

```ts
undefined
```
