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

# 其他配置

这里展示了 Rspack 支持的其余配置项。

## amd


[Added in v1.3.0](https://github.com/web-infra-dev/rspack/releases/tag/v1.3.0)

- **类型：** `false | Record<string, any>`
- **默认值：** `false`

:::info
与 webpack 不同，webpack 中 `amd` 选项的默认值为 `{}`， 即默认开启了 AMD 模块的依赖分析。但由于 AMD 模块的使用量正在逐步减少，Rspack 将 `amd` 选项的默认值设置为 `false`，即默认关闭了 AMD 模块的依赖分析。如果你的项目需要使用 AMD 模块，可以自行开启该选项。
:::

开启此选项可以支持 AMD 模块的依赖分析，这对于兼容一些按照 AMD 规范编写的老旧库很有帮助。

```js title="rspack.config.mjs"
export default {
  amd: {}, // 开启 AMD 模块的依赖分析
};
```

另外可以通过该配置设置 `require.amd` 或 `define.amd` 的值：

```js title="rspack.config.mjs"
export default {
  amd: {
    jQuery: true, // require.amd 和 define.amd 被设置为 { jQuery: true }
  },
};
```

## bail


- 类型： `boolean`
- 默认值：`false`


遇到第一个错误时退出。Rspack 在默认情况下会在命令行以及在 HMR 时的浏览器 console 中打印这些错误，并且继续编译。

```js title="rspack.config.mjs"
export default {
  bail: true,
};
```

这会强制 Rspack 终止编译流程。

## dependencies


- 类型： `string[]`
- 默认值：`undefined`


定义当前配置依赖的所有相邻配置的 [name](#name)。依赖的配置需要先编译完成。

在 watch 模式下，当以下情况发生时，依赖关系将使编译器无效：

1. 依赖的配置已更改。
2. 依赖的配置正在编译中或无效。

请记住，当前配置在其依赖项完成之前不会编译。

```js title="rspack.config.mjs"
export default [
  {
    name: 'client',
    target: 'web',
  },
  {
    name: 'server',
    target: 'node',
    dependencies: ['client'],
  },
];
```

## ignoreWarnings

- **类型：**

```ts
type IgnoreWarnings = (
  | RegExp
  | {
      file?: RegExp;
      message?: RegExp;
      module?: RegExp;
    }
  | ((warning: WebpackError, compilation: Compilation) => boolean)
)[];
```

- **默认值：** `undefined`

用于在构建过程中忽略特定的编译警告。你可以通过匹配警告的 `message`、`module` 或 `file`，或者提供一个自定义函数，来决定哪些警告应被忽略。

使用正则表达式来匹配警告的 `message` 字段：

```js title="rspack.config.mjs"
export default {
  ignoreWarnings: [/warning from compiler/, /other warning/],
};
```

通过对象形式，可以分别对 `message`、`file` 或 `module` 等字段进行匹配：

```js title="rspack.config.mjs"
export default {
  ignoreWarnings: [
    { message: /warning from compiler/ },
    { file: /node_modules/ },
  ],
};
```

当需要更灵活的控制逻辑时，可以使用函数形式。返回 `true` 表示忽略该警告。

```js title="rspack.config.mjs"
export default {
  ignoreWarnings: [
    (warning, compilation) => {
      return /warning from compiler/.test(warning.message || '');
    },
  ],
};
```

## name


- 类型： `string`
- 默认值：`undefined`


配置的名称。当加载多个配置时被使用。

```js title="rspack.config.mjs"
export default {
  name: 'admin-app',
};
```

### loader


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


将自定义值添加到 [Loader 上下文](/zh/api/loader-api/context.md)。

如下示例在 Loader 上下问中定义了一个新变量 `answer`：

```js title="rspack.config.mjs"
export default {
  loader: {
    answer: 42,
  },
};
```

通过 `this.answer` 在 Loader 中获取该变量：

```js title="custom-loader.mjs"
export default function (source) {
  console.log(this.answer); // 打印 `42`
  return source;
}
```

:::tip
你可以覆盖 Loader 上下文中的属性，因为 Rspack 会将所有定义在 Loader 上的属性复制到 Loader 上下文中。
:::


本页改编自 [webpack 文档](https://webpack.js.org/configuration/other-options/)，遵循 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)，且已作修改。

