From 829c0b3765072ba0936b6a22340a56300a9abffb Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 12 Dec 2025 22:24:46 +0800 Subject: [PATCH 1/6] docs: enhance ignoreWarnings section with detailed examples --- website/docs/en/config/other-options.mdx | 49 ++++++++++++++++++--- website/docs/zh/config/other-options.mdx | 55 +++++++++++++++++++++--- 2 files changed, 90 insertions(+), 14 deletions(-) diff --git a/website/docs/en/config/other-options.mdx b/website/docs/en/config/other-options.mdx index e92c575fd1cd..d4b64a74e142 100644 --- a/website/docs/en/config/other-options.mdx +++ b/website/docs/en/config/other-options.mdx @@ -87,17 +87,52 @@ export default [ ## ignoreWarnings - +- **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 message via `message` or `file`: + +```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 || ''); + }, + ], }; ``` diff --git a/website/docs/zh/config/other-options.mdx b/website/docs/zh/config/other-options.mdx index a08afceb86ac..e8479f0f1159 100644 --- a/website/docs/zh/config/other-options.mdx +++ b/website/docs/zh/config/other-options.mdx @@ -86,17 +86,58 @@ export default [ ## ignoreWarnings - +下面是对应的中文翻译,力求准确、清晰,并贴近实际使用语义。 + +--- + +## ignoreWarnings -告知 Rspack 忽略特定的警告。 +- **类型:** + +```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/, warning => true], + ignoreWarnings: [/warning from compiler/, /other warning/], +}; +``` + +通过对象形式,可以分别对 `message` 或 `file` 等字段进行匹配: + +```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 || ''); + }, + ], }; ``` From 6d7fc80672ef840af6238f1c71ad78d9a8f6aec3 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 12 Dec 2025 22:25:53 +0800 Subject: [PATCH 2/6] docs: fix --- website/docs/zh/config/other-options.mdx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/website/docs/zh/config/other-options.mdx b/website/docs/zh/config/other-options.mdx index e8479f0f1159..2813c7ad7d3b 100644 --- a/website/docs/zh/config/other-options.mdx +++ b/website/docs/zh/config/other-options.mdx @@ -86,12 +86,6 @@ export default [ ## ignoreWarnings -下面是对应的中文翻译,力求准确、清晰,并贴近实际使用语义。 - ---- - -## ignoreWarnings - - **类型:** ```ts From 27810ff450f55236125741e9f3795f6af4063dc1 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 12 Dec 2025 22:28:00 +0800 Subject: [PATCH 3/6] docs: jsdoc --- packages/rspack/src/config/types.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/rspack/src/config/types.ts b/packages/rspack/src/config/types.ts index c3244bc3905b..8c3d21e81520 100644 --- a/packages/rspack/src/config/types.ts +++ b/packages/rspack/src/config/types.ts @@ -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; /** From d7e3cb4a21cee1000eac2b89a7af3087924540fe Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 13 Dec 2025 11:06:20 +0800 Subject: [PATCH 4/6] Update website/docs/en/config/other-options.mdx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- website/docs/en/config/other-options.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/en/config/other-options.mdx b/website/docs/en/config/other-options.mdx index d4b64a74e142..7523ab789292 100644 --- a/website/docs/en/config/other-options.mdx +++ b/website/docs/en/config/other-options.mdx @@ -113,7 +113,7 @@ export default { }; ``` -Use an object to match the warning message via `message` or `file`: +Use an object to match the warning via `message`, `file`, or `module`: ```js title="rspack.config.mjs" export default { From 597286c2cf92c1e92399ca2476c26a98eb00ae58 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 13 Dec 2025 11:06:27 +0800 Subject: [PATCH 5/6] Update website/docs/zh/config/other-options.mdx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- website/docs/zh/config/other-options.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/zh/config/other-options.mdx b/website/docs/zh/config/other-options.mdx index 2813c7ad7d3b..59e30347615d 100644 --- a/website/docs/zh/config/other-options.mdx +++ b/website/docs/zh/config/other-options.mdx @@ -112,7 +112,7 @@ export default { }; ``` -通过对象形式,可以分别对 `message` 或 `file` 等字段进行匹配: +通过对象形式,可以分别对 `message`、`file` 或 `module` 等字段进行匹配: ```js title="rspack.config.mjs" export default { From e6ab3e53be4e04f1b3167609e9cfdceb1da532a6 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 13 Dec 2025 11:06:58 +0800 Subject: [PATCH 6/6] Update website/docs/zh/config/other-options.mdx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- website/docs/zh/config/other-options.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/zh/config/other-options.mdx b/website/docs/zh/config/other-options.mdx index 59e30347615d..4d1d2a0e53d8 100644 --- a/website/docs/zh/config/other-options.mdx +++ b/website/docs/zh/config/other-options.mdx @@ -104,7 +104,7 @@ type IgnoreWarnings = ( 用于在构建过程中忽略特定的编译警告。你可以通过匹配警告的 `message`、`module` 或 `file`,或者提供一个自定义函数,来决定哪些警告应被忽略。 -使用正则表达式时来匹配警告的 `message` 字段: +使用正则表达式来匹配警告的 `message` 字段: ```js title="rspack.config.mjs" export default {