Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update source.exclude usage #3517

Merged
merged 3 commits into from
Sep 20, 2024
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
22 changes: 22 additions & 0 deletions website/docs/en/config/source/exclude.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 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).

```ts
export default {
tools: {
rspack: (config, { rspack }) => {
config.plugins?.push(
new rspack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
);
return config;
},
},
};
```
22 changes: 22 additions & 0 deletions website/docs/zh/config/source/exclude.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
},
};
```
Loading