@rspack/plugin-react-refresh 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,3 @@
1
- <picture>
2
- <source media="(prefers-color-scheme: dark)" srcset="https://assets.rspack.dev/rspack/rspack-banner-plain-dark.png">
3
- <img alt="Rspack Banner" src="https://assets.rspack.dev/rspack/rspack-banner-plain-light.png">
4
- </picture>
5
-
6
1
  # @rspack/plugin-react-refresh
7
2
 
8
3
  <p>
@@ -95,19 +90,19 @@ Compared to the previous approach, this method decouples the React Fast Refresh
95
90
 
96
91
  ## Example
97
92
 
98
- - For usage with `builtin:swc-loader`, you can refer to the example at [examples/react-refresh](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/react-refresh/rspack.config.js), When using with `swc-loader`, simply replace `builtin:swc-loader` with `swc-loader`.
99
- - For usage with `babel-loader`, you can refer to the example at [examples/react-refresh-babel-loader](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/react-refresh-babel-loader/rspack.config.js)
93
+ - For usage with `builtin:swc-loader`, you can refer to the example at [examples/react-refresh](https://github.com/rstackjs/rspack-examples/tree/main/rspack/react-refresh/rspack.config.js), When using with `swc-loader`, simply replace `builtin:swc-loader` with `swc-loader`.
94
+ - For usage with `babel-loader`, you can refer to the example at [examples/react-refresh-babel-loader](https://github.com/rstackjs/rspack-examples/tree/main/rspack/react-refresh-babel-loader/rspack.config.js)
100
95
 
101
96
  ## Options
102
97
 
103
98
  ### test
104
99
 
105
- - Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
100
+ - Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)
106
101
  - Default: `undefined`
107
102
 
108
103
  Specifies which files should be processed by the React Refresh loader. This option is passed to the `builtin:react-refresh-loader` as the `rule.test` condition.
109
104
 
110
- Works identically to Rspack's [rule.test](https://rspack.dev/config/module#ruletest) option.
105
+ Works identically to Rspack's [rule.test](https://rspack.rs/config/module-rules#rulestest) option.
111
106
 
112
107
  ```js
113
108
  new ReactRefreshPlugin({
@@ -117,14 +112,14 @@ new ReactRefreshPlugin({
117
112
 
118
113
  ### include
119
114
 
120
- - Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
115
+ - Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)
121
116
  - Default: `/\.([cm]js|[jt]sx?|flow)$/i`
122
117
 
123
118
  Explicitly includes files to be processed by the React Refresh loader. This option is passed to the `builtin:react-refresh-loader` as the `rule.include` condition.
124
119
 
125
120
  Use this to limit processing to specific directories or file patterns.
126
121
 
127
- Works identically to Rspack's [rule.include](https://rspack.dev/config/module#ruleinclude) option.
122
+ Works identically to Rspack's [rule.include](https://rspack.rs/config/module-rules#rulesinclude) option.
128
123
 
129
124
  ```js
130
125
  new ReactRefreshPlugin({
@@ -134,10 +129,10 @@ new ReactRefreshPlugin({
134
129
 
135
130
  ### exclude
136
131
 
137
- - Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
132
+ - Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)
138
133
  - Default: `/node_modules/`
139
134
 
140
- 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.
135
+ Exclude files from being processed by the plugin. The value is the same as the [rule.exclude](https://rspack.rs/config/module-rules#rulesexclude) option in Rspack.
141
136
 
142
137
  ```js
143
138
  new ReactRefreshPlugin({
@@ -147,10 +142,10 @@ new ReactRefreshPlugin({
147
142
 
148
143
  ### resourceQuery
149
144
 
150
- - Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)
145
+ - Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)
151
146
  - Default: `undefined`
152
147
 
153
- 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.
148
+ 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.rs/config/module-rules#rulesresourcequery) option in Rspack.
154
149
 
155
150
  For example, to exclude all resources with the `raw` query, such as `import rawTs from './ReactComponent.ts?raw';`, use the following:
156
151
 
@@ -197,7 +192,7 @@ It is most useful when multiple instances of React Refresh is running together s
197
192
 
198
193
  Modify the behavior of the error overlay.
199
194
 
200
- Checkout [OverlayOptions](https://github.com/rspack-contrib/rspack-plugin-react-refresh/blob/main/src/options.ts#L4) type signature for more details.
195
+ Checkout [OverlayOptions](https://github.com/rstackjs/rspack-plugin-react-refresh/blob/main/src/options.ts#L4) type signature for more details.
201
196
 
202
197
  - Enable the error overlay:
203
198
 
@@ -232,6 +227,21 @@ new ReactRefreshPlugin({
232
227
  });
233
228
  ```
234
229
 
230
+ ### reactRefreshLoader
231
+
232
+ - Type: `string`
233
+ - Default: `builtin:react-refresh-loader`
234
+
235
+ Be default, the plugin uses `builtin:react-refresh-loader` loader implementation [from Rspack](https://github.com/web-infra-dev/rspack/tree/main/crates/rspack_loader_react_refresh) in order ot inject
236
+ the React Refresh utilities into each module. `reactRefreshLoader` option allows to specify the loader, that implements
237
+ custom React Refresh instrumentation if needed.
238
+
239
+ ```js
240
+ new ReactRefreshPlugin({
241
+ reactRefreshLoader: 'my-advanced-react-refresh-loader',
242
+ });
243
+ ```
244
+
235
245
  ## Credits
236
246
 
237
247
  Thanks to the [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) created by [@pmmmwh](https://github.com/pmmmwh), which inspires implement this plugin.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,6 @@ declare class ReactRefreshRspackPlugin {
7
7
  * @deprecated
8
8
  */
9
9
  static get deprecated_runtimePaths(): string[];
10
- static loader: string;
11
10
  constructor(options?: PluginOptions);
12
11
  apply(compiler: Compiler): void;
13
12
  }
package/dist/index.js CHANGED
@@ -63,6 +63,7 @@ function normalizeOptions(options) {
63
63
  d(options, 'injectLoader', true);
64
64
  d(options, 'injectEntry', true);
65
65
  d(options, 'reloadOnRuntimeErrors', false);
66
+ d(options, 'reactRefreshLoader', 'builtin:react-refresh-loader');
66
67
  options.overlay = normalizeOverlay(options.overlay);
67
68
  return options;
68
69
  }
@@ -181,7 +182,6 @@ class ReactRefreshRspackPlugin {
181
182
  static get deprecated_runtimePaths() {
182
183
  return getRefreshRuntimePaths();
183
184
  }
184
- static loader = 'builtin:react-refresh-loader';
185
185
  constructor(options = {}){
186
186
  this.options = normalizeOptions(options);
187
187
  }
@@ -214,7 +214,7 @@ class ReactRefreshRspackPlugin {
214
214
  'url'
215
215
  ]
216
216
  },
217
- use: ReactRefreshRspackPlugin.loader
217
+ use: this.options.reactRefreshLoader
218
218
  });
219
219
  const definedModules = {
220
220
  __react_refresh_library__: JSON.stringify(compiler.rspack.Template.toIdentifier(this.options.library || compiler.options.output.uniqueName || compiler.options.output.library)),
package/dist/options.d.ts CHANGED
@@ -14,7 +14,7 @@ export type PluginOptions = {
14
14
  * Specifies which files should be processed by the React Refresh loader.
15
15
  * This option is passed to the `builtin:react-refresh-loader` as the `rule.test` condition.
16
16
  * Works identically to Rspack's `rule.test` option.
17
- * @see https://rspack.dev/config/module#ruletest
17
+ * @see https://rspack.rs/config/module-rules#rulestest
18
18
  */
19
19
  test?: RuleSetCondition;
20
20
  /**
@@ -23,20 +23,20 @@ export type PluginOptions = {
23
23
  * Use this to limit processing to specific directories or file patterns.
24
24
  * Works identically to Rspack's `rule.include` option.
25
25
  * @default /\.([cm]js|[jt]sx?|flow)$/i
26
- * @see https://rspack.dev/config/module#ruleinclude
26
+ * @see https://rspack.rs/config/module-rules#rulesinclude
27
27
  */
28
28
  include?: RuleSetCondition | null;
29
29
  /**
30
30
  * Exclude files from being processed by the plugin.
31
31
  * The value is the same as the `rule.exclude` option in Rspack.
32
32
  * @default /node_modules/
33
- * @see https://rspack.dev/config/module#ruleexclude
33
+ * @see https://rspack.rs/config/module-rules#rulesexclude
34
34
  */
35
35
  exclude?: RuleSetCondition | null;
36
36
  /**
37
37
  * Can be used to exclude certain resources from being processed by
38
38
  * the plugin by the resource query.
39
- * @see https://rspack.dev/config/module#ruleresourcequery
39
+ * @see https://rspack.rs/config/module-rules#rulesresourcequery
40
40
  *
41
41
  * @example
42
42
  * To exclude all resources with the `raw` query, such as
@@ -80,6 +80,11 @@ export type PluginOptions = {
80
80
  * @default false
81
81
  */
82
82
  reloadOnRuntimeErrors?: boolean;
83
+ /**
84
+ * Allows to specify custom react-refresh loader
85
+ * @default "builtin:react-refresh-loader"
86
+ */
87
+ reactRefreshLoader?: string;
83
88
  };
84
89
  export interface NormalizedPluginOptions extends Required<PluginOptions> {
85
90
  overlay: false | OverlayOptions;
@@ -69,7 +69,7 @@ function getSocketUrlParts(resourceQuery, metadata = {}) {
69
69
  if (isEmptyHostname && window.location.hostname && 0 === window.location.protocol.indexOf('http')) urlParts.hostname = window.location.hostname;
70
70
  if (!urlParts.protocol || urlParts.hostname && (isEmptyHostname || 'https:' === window.location.protocol)) urlParts.protocol = window.location.protocol;
71
71
  if (!urlParts.port) urlParts.port = window.location.port;
72
- if (!urlParts.hostname || !urlParts.pathname) throw new Error("[React Refresh] Failed to get an URL for the socket connection.\nThis usually means that the current executed script doesn't have a `src` attribute set.\nYou should either specify the socket path parameters under the `devServer` key in your Rspack config, or use the `overlay` option.\nhttps://www.rspack.dev/guide/tech/react#fast-refresh");
72
+ if (!urlParts.hostname || !urlParts.pathname) throw new Error("[React Refresh] Failed to get an URL for the socket connection.\nThis usually means that the current executed script doesn't have a `src` attribute set.\nYou should either specify the socket path parameters under the `devServer` key in your Rspack config, or use the `overlay` option.\nhttps://rspack.rs/guide/tech/react#fast-refresh");
73
73
  return {
74
74
  auth: urlParts.auth,
75
75
  hostname: urlParts.hostname,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rspack/plugin-react-refresh",
3
- "version": "1.5.3",
4
- "repository": "https://github.com/rspack-contrib/rspack-plugin-react-refresh",
3
+ "version": "1.6.0",
4
+ "repository": "https://github.com/rstackjs/rspack-plugin-react-refresh",
5
5
  "license": "MIT",
6
6
  "description": "React refresh plugin for Rspack",
7
7
  "main": "exports/index.cjs",
@@ -32,16 +32,16 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@biomejs/biome": "^1.9.4",
35
- "@rslib/core": "^0.17.0",
36
- "@rspack/core": "^1.6.0",
37
- "@rstest/core": "^0.6.1",
38
- "@types/node": "^22.18.13",
39
- "bumpp": "^10.3.1",
35
+ "@rslib/core": "^0.18.2",
36
+ "@rspack/core": "^1.6.5",
37
+ "@rstest/core": "^0.6.8",
38
+ "@types/node": "^24.10.1",
39
+ "bumpp": "^10.3.2",
40
40
  "cac": "^6.7.14",
41
41
  "cross-env": "^10.1.0",
42
- "execa": "9.6.0",
42
+ "execa": "9.6.1",
43
43
  "fs-extra": "11.3.2",
44
- "nano-staged": "^0.8.0",
44
+ "nano-staged": "^0.9.0",
45
45
  "react-refresh": "^0.18.0",
46
46
  "semver": "7.7.3",
47
47
  "simple-git-hooks": "^2.13.1",