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
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Compared to the previous approach, this method decouples the React Fast Refresh
- Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
- Default: `/\.([cm]js|[jt]sx?|flow)$/i`

Include files to be processed by the plugin. The value is the same as the `rule.test` option in Rspack.
Include files to be processed by the plugin. The value is the same as the [rule.test](https://rspack.dev/config/module#ruletest) option in Rspack.

```js
new ReactRefreshPlugin({
Expand All @@ -121,14 +121,29 @@ new ReactRefreshPlugin({
- Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
- Default: `/node_modules/`

Exclude files from being processed by the plugin. The value is the same as the `rule.exclude` option in Rspack.
Exclude files from being processed by the plugin. The value is the same as the [rule.exclude](https://rspack.dev/config/module#ruleexclude) option in Rspack.

```js
new ReactRefreshPlugin({
exclude: [/node_modules/, /some-other-module/],
});
```

### resourceQuery

- Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
- Default: `undefined`

Can be used to exclude certain resources from being processed by the plugin by the resource query. The value is the same as the [rule.resourceQuery](https://rspack.dev/config/module#ruleresourcequery) option in Rspack.

For example, to exclude all resources with the `raw` query, such as `import rawTs from './ReactComponent.ts?raw';`, use the following:

```js
new ReactRefreshPlugin({
resourceQuery: { not: /raw/ },
});
```

### forceEnable

- Type: `boolean`
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ReactRefreshRspackPlugin {
// biome-ignore lint: exists
or: [this.options.exclude!, [...runtimePaths]].filter(Boolean),
},
resourceQuery: this.options.resourceQuery,
use: ReactRefreshRspackPlugin.loader,
});
}
Expand Down
15 changes: 15 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ export type PluginOptions = {
* Include files to be processed by the plugin.
* The value is the same as the `rule.test` option in Rspack.
* @default /\.([cm]js|[jt]sx?|flow)$/i
* @see https://rspack.dev/config/module#ruletest
*/
include?: RuleSetCondition | null;
/**
* Exclude files from being processed by the plugin.
* The value is the same as the `rule.exclude` option in Rspack.
* @default /node_modules/
* @see https://rspack.dev/config/module#ruleexclude
*/
exclude?: RuleSetCondition | null;
/**
* Can be used to exclude certain resources from being processed by
* the plugin by the resource query.
* @see https://rspack.dev/config/module#ruleresourcequery
*
* @example
* To exclude all resources with the `raw` query, such as
* `import rawTs from './ReactComponent.ts?raw';`, use the following:
* ```ts
* { resourceQuery: { not: /raw/ } }
* ```
*/
resourceQuery?: RuleSetCondition;
/**
* Sets a namespace for the React Refresh runtime.
* It is most useful when multiple instances of React Refresh is running
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/query/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'foo';
1 change: 1 addition & 0 deletions test/fixtures/query/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./foo?raw');
Loading