> 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.

# dev.writeToDisk

> `optional` **writeToDisk?**: `boolean` | ((`filename`: `string`) => `boolean`)

:::info Lynx 默认值覆盖
此项是 Rsbuild 配置，`pluginLynx` 覆盖了它的默认值。下方默认值指应用插件后的值。请在 `rsbuild.config.ts` 顶层配置，显式设置的值优先。

[完整行为见 Rsbuild 配置参考](https://rsbuild.rs/zh/config/dev/write-to-disk)。
:::

用于控制是否将开发环境的构建产物写入磁盘。

## Default Value

```ts
true
```

## Remarks

该选项会透传给 [\`webpack-dev-middleware\`](https://github.com/webpack/webpack-dev-middleware?tab=readme-ov-file#writetodisk)。

设置 `writeToDisk: true` 不会改变 `webpack-dev-middleware` 的行为，通过浏览器访问的 bundle 文件仍然由内存提供。

该选项也接受 `Function` 类型的值，可用于过滤需要写入磁盘的文件。

该函数的逻辑与 `Array#filter` 相同：返回 `false` 时不写入该文件，返回 `true` 时将该文件写入磁盘。

## Example

```js
// lynx.config.ts
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
  dev: {
    writeToDisk: (filePath) => /superman\.css$/.test(filePath),
  },
})
```
