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

# dev.server

- **类型：** `Object`
- **默认值：** `{}`

通过 `dev.server` 可以修改开发环境服务器的配置。

### compress

- **类型：** `boolean`
- **默认值：** `true`

是否对静态资源启用 gzip 压缩。

如果你需要禁用 gzip 压缩，可以将 `compress` 设置为 `false`：

```ts
export default {
  dev: {
    server: {
      compress: false,
    },
  },
};
```

更多详细信息请参考 [Rsbuild - server.compress](https://v2.rsbuild.rs/zh/config/server/compress) 文档。

### headers

- **类型：** `Record<string, string>`
- **默认值：** `undefined`

设置自定义响应头。

```js
export default {
  dev: {
    server: {
      headers: {
        'X-Custom-Foo': 'bar',
      },
    },
  },
};
```

更多详细信息请参考 [Rsbuild - server.headers](https://v2.rsbuild.rs/zh/config/server/headers) 文档。

### historyApiFallback

- **类型：** `boolean | ConnectHistoryApiFallbackOptions`
- **默认值：** `false`

在需要对一些 404 响应或其他请求提供替代页面的场景，可通过 `dev.server.historyApiFallback` 进行设置：

```js
export default {
  dev: {
    server: {
      historyApiFallback: true,
    },
  },
};
```

更多配置选项请参考 [Rsbuild - server.historyApiFallback](https://v2.rsbuild.rs/zh/config/server/history-api-fallback) 文档。

### watch

- **类型：** `boolean`
- **默认值：** `true`

是否监听 `mock/`、`server/`、`api/` 等目录的文件变化。

更多详细信息请参考 [Rsbuild - dev.watchFiles](https://v2.rsbuild.rs/zh/config/dev/watch-files) 文档。

### cors

- **类型:** `boolean | import('cors').CorsOptions`

为开发服务器配置 CORS（跨域资源共享）。

Modern.js 中 `cors` 的默认配置遵循 Rsbuild 的默认值：

```ts
const defaultAllowedOrigins =
  /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;

const defaultOptions = {
  // 默认允许：
  // - localhost
  // - 127.0.0.1
  // - [::1]
  origin: defaultAllowedOrigins,
};
```

更多配置选项和详细用法请参考 [Rsbuild - server.cors](https://v2.rsbuild.rs/zh/config/server/cors) 文档。

### proxy

- **类型：** `ProxyOptions[] | Record<string, string | ProxyOptions>`
- **默认值：** `undefined`

为开发服务器配置代理规则，把请求转发到指定服务。

```js
export default {
  dev: {
    server: {
      proxy: {
        // http://localhost:8080/api -> https://example.com/api
        // http://localhost:8080/api/foo -> https://example.com/api/foo
        '/api': 'https://example.com',
      },
    },
  },
};
```

:::tip
该选项与 Rsbuild 的 `server.proxy` 选项一致，更多用法请参考 [Rsbuild - server.proxy](https://v2.rsbuild.rs/zh/config/server/proxy)。
:::
