From 9fa5f5dbb9aa171e4022202bdda5a19b35a5e329 Mon Sep 17 00:00:00 2001 From: "gaoyuan.1226" Date: Fri, 20 Sep 2024 15:48:35 +0800 Subject: [PATCH 1/3] docs: update source.exclude usage --- website/docs/en/config/source/exclude.mdx | 22 ++++++++++++++++++++++ website/docs/zh/config/source/exclude.mdx | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/website/docs/en/config/source/exclude.mdx b/website/docs/en/config/source/exclude.mdx index 73e7982f46..e9ae4f8863 100644 --- a/website/docs/en/config/source/exclude.mdx +++ b/website/docs/en/config/source/exclude.mdx @@ -18,3 +18,25 @@ export default { ``` > Refer to [source.include](/config/source/include) to learn more. + +### Not compiled vs Not bundled + +`source.exclude` is used to specify JavaScript/TypeScript files that do not need to be compiled. This means that these files will not be translated by `swc` or `babel`, but they will still be bundled into the product (if referenced). + +If you want certain files to be ignored and not bundled into the outputs, you can use Rspack's [IgnorePlugin](https://rspack.dev/plugins/webpack/ignore-plugin). + +```ts +export default { + tools: { + rspack: (config, { rspack }) => { + config.plugins?.push( + new rspack.IgnorePlugin({ + resourceRegExp: /^\.\/locale$/, + contextRegExp: /moment$/, + }), + ); + return config; + }, + }, +}; +``` diff --git a/website/docs/zh/config/source/exclude.mdx b/website/docs/zh/config/source/exclude.mdx index ce7038b9c1..86b5384bb8 100644 --- a/website/docs/zh/config/source/exclude.mdx +++ b/website/docs/zh/config/source/exclude.mdx @@ -18,3 +18,25 @@ export default { ``` > 参考 [source.include](/config/source/include) 来了解更多。 + +### 不编译 vs 不打包 + +`source.exclude` 用于指定不需要编译的 JavaScript/TypeScript 文件。这意味着这些文件不会经过 `swc` / `babel` 转译,但这些文件仍然会被打包到产物中(如果被引用)。 + +如果你希望某些文件在打包过程中被忽略,不被打包到产物中,可以使用 Rspack 的 [IgnorePlugin](https://rspack.dev/zh/plugins/webpack/ignore-plugin)。 + +```ts +export default { + tools: { + rspack: (config, { rspack }) => { + config.plugins?.push( + new rspack.IgnorePlugin({ + resourceRegExp: /^\.\/locale$/, + contextRegExp: /moment$/, + }), + ); + return config; + }, + }, +}; +``` From f189c3876570cd84e71ff152a5f177f01ecc674a Mon Sep 17 00:00:00 2001 From: "gaoyuan.1226" Date: Fri, 20 Sep 2024 15:49:56 +0800 Subject: [PATCH 2/3] docs: outputs --- website/docs/en/config/source/exclude.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/en/config/source/exclude.mdx b/website/docs/en/config/source/exclude.mdx index e9ae4f8863..630f6d36fa 100644 --- a/website/docs/en/config/source/exclude.mdx +++ b/website/docs/en/config/source/exclude.mdx @@ -21,7 +21,7 @@ export default { ### Not compiled vs Not bundled -`source.exclude` is used to specify JavaScript/TypeScript files that do not need to be compiled. This means that these files will not be translated by `swc` or `babel`, but they will still be bundled into the product (if referenced). +`source.exclude` is used to specify JavaScript/TypeScript files that do not need to be compiled. This means that these files will not be translated by `swc` or `babel`, but they will still be bundled into the outputs (if referenced). If you want certain files to be ignored and not bundled into the outputs, you can use Rspack's [IgnorePlugin](https://rspack.dev/plugins/webpack/ignore-plugin). From c9bacc1f6581c824cb39764660e72043570e5f47 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 20 Sep 2024 10:21:17 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- website/docs/en/config/source/exclude.mdx | 2 +- website/docs/zh/config/source/exclude.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/en/config/source/exclude.mdx b/website/docs/en/config/source/exclude.mdx index 630f6d36fa..c74e3032b5 100644 --- a/website/docs/en/config/source/exclude.mdx +++ b/website/docs/en/config/source/exclude.mdx @@ -21,7 +21,7 @@ export default { ### Not compiled vs Not bundled -`source.exclude` is used to specify JavaScript/TypeScript files that do not need to be compiled. This means that these files will not be translated by `swc` or `babel`, but they will still be bundled into the outputs (if referenced). +`source.exclude` is used to specify JavaScript/TypeScript files that do not need to be compiled. This means that these files will not be translated by SWC or Babel, but they will still be bundled into the outputs (if referenced). If you want certain files to be ignored and not bundled into the outputs, you can use Rspack's [IgnorePlugin](https://rspack.dev/plugins/webpack/ignore-plugin). diff --git a/website/docs/zh/config/source/exclude.mdx b/website/docs/zh/config/source/exclude.mdx index 86b5384bb8..40195e5c78 100644 --- a/website/docs/zh/config/source/exclude.mdx +++ b/website/docs/zh/config/source/exclude.mdx @@ -21,7 +21,7 @@ export default { ### 不编译 vs 不打包 -`source.exclude` 用于指定不需要编译的 JavaScript/TypeScript 文件。这意味着这些文件不会经过 `swc` / `babel` 转译,但这些文件仍然会被打包到产物中(如果被引用)。 +`source.exclude` 用于指定不需要编译的 JavaScript/TypeScript 文件。这意味着这些文件不会经过 SWC 或 Babel 转译,但这些文件仍然会被打包到产物中(如果被引用)。 如果你希望某些文件在打包过程中被忽略,不被打包到产物中,可以使用 Rspack 的 [IgnorePlugin](https://rspack.dev/zh/plugins/webpack/ignore-plugin)。