Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3057,7 +3057,18 @@ export type RspackOptions = {
*/
loader?: Loader;
/**
* Warnings to ignore during compilation.
* Tells Rspack to suppress specific compilation warnings by matching their
* message, module, or file, or by using a custom function.
*
* @example
* ```js
* export default {
* ignoreWarnings: [
* /warning from compiler/,
* { file: /node_modules/ },
* ],
* };
* ```
*/
ignoreWarnings?: IgnoreWarnings;
/**
Expand Down
49 changes: 42 additions & 7 deletions website/docs/en/config/other-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,52 @@ export default [

## ignoreWarnings

<PropertyType
type="(RegExp | ((warning: Error, Compilation: Compilation) => boolean))[]"
defaultValueList={[{ defaultValue: 'undefined' }]}
/>
- **Type:**

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

- **Default:** `undefined`

Tells Rspack to ignore specific warnings.
Tells Rspack to suppress specific compilation warnings by matching their message, module, or file, or by using a custom function.

Use a RegExp to match the warning message:

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

Use an object to match the warning via `message`, `file`, or `module`:

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

Use a function for full control. Return `true` to ignore the warning:

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

Expand Down
49 changes: 42 additions & 7 deletions website/docs/zh/config/other-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,52 @@ export default [

## ignoreWarnings

<PropertyType
type="(RegExp | ((warning: Error, Compilation: Compilation) => boolean))[]"
defaultValueList={[{ defaultValue: 'undefined' }]}
/>
- **类型:**

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

- **默认值:** `undefined`

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

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

```js title="rspack.config.mjs"
export default {
//...
ignoreWarnings: [/warning from compiler/, warning => true],
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 || '');
},
],
};
```

Expand Down
Loading