@rspack/plugin-react-refresh 1.5.2 → 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.
@@ -1,13 +1,4 @@
1
1
  /* global __react_refresh_error_overlay__, __react_refresh_socket__, __resourceQuery */
2
- /**
3
- * The following code is modified based on
4
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f1c8b9a44198449093ca95f85af5df97925e1cfc/client/ErrorOverlayEntry.js
5
- *
6
- * MIT Licensed
7
- * Author Michael Mok
8
- * Copyright (c) 2019 Michael Mok
9
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/LICENSE
10
- */
11
2
  const events = require('./utils/errorEventHandlers.js');
12
3
  const formatWebpackErrors = require('./utils/formatWebpackErrors.js');
13
4
  const runWithRetry = require('./utils/retry.js');
@@ -1,12 +1,3 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f1c8b9a44198449093ca95f85af5df97925e1cfc/overlay/index.js
4
- *
5
- * MIT Licensed
6
- * Author Michael Mok
7
- * Copyright (c) 2019 Michael Mok
8
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/LICENSE
9
- */
10
1
  const RuntimeErrorFooter = require('./components/RuntimeErrorFooter.js');
11
2
  const RuntimeErrorHeader = require('./components/RuntimeErrorHeader.js');
12
3
  const CompileErrorContainer = require('./containers/CompileErrorContainer.js');
@@ -1,8 +1,6 @@
1
- // Thanks https://github.com/pmmmwh/react-refresh-webpack-plugin
2
1
  const RefreshUtils = require('./refreshUtils');
3
2
  const RefreshRuntime = require('react-refresh/runtime');
4
3
 
5
- // Port from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/loader/utils/getRefreshModuleRuntime.js#L29
6
4
  function refresh(moduleId, webpackHot) {
7
5
  const currentExports = RefreshUtils.getModuleExports(moduleId);
8
6
  const fn = (exports) => {
@@ -1,13 +1,3 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/client/ReactRefreshEntry.js
4
- *
5
- * MIT Licensed
6
- * Author Michael Mok
7
- * Copyright (c) 2019 Michael Mok
8
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/LICENSE
9
- */
10
-
11
1
  var RefreshRuntime = require('react-refresh/runtime');
12
2
  var safeThis = (function () {
13
3
  // copied from core-js-pure/features/global-this
@@ -1,13 +1,3 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/lib/runtime/RefreshUtils.js
4
- *
5
- * MIT Licensed
6
- * Author Michael Mok
7
- * Copyright (c) 2019 Michael Mok
8
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/LICENSE
9
- */
10
-
11
1
  /* global __webpack_require__ */
12
2
  var Refresh = require('react-refresh/runtime');
13
3
 
@@ -1,15 +1,8 @@
1
1
  /* eslint-disable */
2
2
  // @ts-nocheck
3
3
  /**
4
- * The following code is modified based on
5
- * https://github.com/mahdyar/ansi-html-community/blob/b86cc3f1fa1d118477877352f0eafe1a70fd20ab/index.js
6
- *
7
- * Supported:
8
- * - added support for 24-bit RGB colors.
9
- *
10
- * Apache 2.0 Licensed
11
- * Author @Tjatse
12
- * https://github.com/mahdyar/ansi-html-community/blob/master/LICENSE
4
+ * The following code is modified based on mahdyar/ansi-html-community
5
+ * Added support for 24-bit RGB colors.
13
6
  */
14
7
  'use strict';
15
8
 
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
  }
@@ -167,7 +168,7 @@ function getSocketIntegration(integrationType) {
167
168
  return resolvedSocketIntegration;
168
169
  }
169
170
  function addEntry(entry, compiler) {
170
- new compiler.webpack.EntryPlugin(compiler.context, entry, {
171
+ new compiler.rspack.EntryPlugin(compiler.context, entry, {
171
172
  name: void 0
172
173
  }).apply(compiler);
173
174
  }
@@ -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
  }
@@ -194,7 +194,7 @@ class ReactRefreshRspackPlugin {
194
194
  if (this.options.injectEntry) for (const entry of addEntries.prependEntries)addEntry(entry, compiler);
195
195
  if (false !== this.options.overlay && this.options.overlay.sockIntegration) addSocketEntry(this.options.overlay.sockIntegration, compiler);
196
196
  for (const entry of addEntries.overlayEntries)addEntry(entry, compiler);
197
- new compiler.webpack.ProvidePlugin({
197
+ new compiler.rspack.ProvidePlugin({
198
198
  $ReactRefreshRuntime$: reactRefreshPath
199
199
  }).apply(compiler);
200
200
  if (this.options.injectLoader) compiler.options.module.rules.unshift({
@@ -214,10 +214,10 @@ 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
- __react_refresh_library__: JSON.stringify(compiler.webpack.Template.toIdentifier(this.options.library || compiler.options.output.uniqueName || compiler.options.output.library)),
220
+ __react_refresh_library__: JSON.stringify(compiler.rspack.Template.toIdentifier(this.options.library || compiler.options.output.uniqueName || compiler.options.output.library)),
221
221
  __reload_on_runtime_errors__: this.options.reloadOnRuntimeErrors
222
222
  };
223
223
  const providedModules = {
@@ -230,8 +230,8 @@ class ReactRefreshRspackPlugin {
230
230
  if (this.options.overlay.module) providedModules.__react_refresh_error_overlay__ = require.resolve(this.options.overlay.module);
231
231
  if (this.options.overlay.sockIntegration) providedModules.__react_refresh_socket__ = getSocketIntegration(this.options.overlay.sockIntegration);
232
232
  }
233
- new compiler.webpack.DefinePlugin(definedModules).apply(compiler);
234
- new compiler.webpack.ProvidePlugin(providedModules).apply(compiler);
233
+ new compiler.rspack.DefinePlugin(definedModules).apply(compiler);
234
+ new compiler.rspack.ProvidePlugin(providedModules).apply(compiler);
235
235
  compiler.options.resolve.alias = {
236
236
  'react-refresh': getRefreshRuntimeDirPath(),
237
237
  ...compiler.options.resolve.alias
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;
@@ -1,15 +1,5 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f770d3962c388da01eeda7079bff5f40c93992d2/sockets/WHMEventSource.js
4
- *
5
- * MIT Licensed
6
- * Author Michael Mok
7
- * Copyright (c) 2019 Michael Mok
8
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f770d3962c388da01eeda7079bff5f40c93992d2/LICENSE
9
- */
10
1
  /**
11
2
  * The hard-coded singleton key for webpack-hot-middleware's client instance.
12
- *
13
3
  * [Ref](https://github.com/webpack-contrib/webpack-hot-middleware/blob/cb29abb9dde435a1ac8e9b19f82d7d36b1093198/client.js#L152)
14
4
  */
15
5
  declare const singletonKey = "__webpack_hot_middleware_reporter__";
@@ -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.2",
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,25 +32,21 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@biomejs/biome": "^1.9.4",
35
- "@rslib/core": "^0.15.1",
36
- "@rspack/core": "^1.5.8",
37
- "@types/jest": "29.5.14",
38
- "@types/node": "^22.17.0",
39
- "bumpp": "^10.2.3",
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
- "cross-env": "^10.0.0",
42
- "execa": "9.6.0",
43
- "fs-extra": "11.3.0",
44
- "jest": "29.7.0",
45
- "jest-cli": "29.7.0",
46
- "jest-environment-node": "29.7.0",
47
- "nano-staged": "^0.8.0",
48
- "react-refresh": "^0.17.0",
49
- "semver": "7.7.2",
41
+ "cross-env": "^10.1.0",
42
+ "execa": "9.6.1",
43
+ "fs-extra": "11.3.2",
44
+ "nano-staged": "^0.9.0",
45
+ "react-refresh": "^0.18.0",
46
+ "semver": "7.7.3",
50
47
  "simple-git-hooks": "^2.13.1",
51
- "ts-jest": "29.4.0",
52
48
  "ts-node": "^10.9.2",
53
- "typescript": "5.9.2"
49
+ "typescript": "5.9.3"
54
50
  },
55
51
  "dependencies": {
56
52
  "error-stack-parser": "^2.1.4",
@@ -74,7 +70,7 @@
74
70
  "dev": "rslib build -w",
75
71
  "lint": "biome check .",
76
72
  "lint:write": "biome check . --write",
77
- "test": "jest --colors",
73
+ "test": "rstest",
78
74
  "release": "node ./scripts/release.mjs",
79
75
  "bump": "npx bumpp --no-push --no-tag --no-commit"
80
76
  }