@rspack/plugin-react-refresh 2.0.0 → 2.0.2

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
@@ -11,7 +11,7 @@ React refresh plugin for [Rspack](https://github.com/web-infra-dev/rspack).
11
11
  ## Versions
12
12
 
13
13
  - `2.x`: For Rspack v2.
14
- - `1.x`: For Rspack v1, see [v1.x - README](https://github.com/rstackjs/rspack-dev-server/tree/v1.x#rspackdev-server) for usage guide.
14
+ - `1.x`: For Rspack v1, see [v1.x - README](https://github.com/rstackjs/rspack-plugin-react-refresh/tree/v1.x?tab=readme-ov-file#rspackplugin-react-refresh) for usage guide.
15
15
 
16
16
  ## Installation
17
17
 
@@ -37,10 +37,10 @@ import { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';
37
37
 
38
38
  ## Usage
39
39
 
40
- Enabling [React Fast Refresh](https://reactnative.dev/docs/fast-refresh) functionality primarily involves two aspects: code injection and code transformation.
40
+ To enable [React Fast Refresh](https://reactnative.dev/docs/fast-refresh), you need both runtime injection and source transformation.
41
41
 
42
- - Code injection will inject some code from the [react-refresh](https://www.npmjs.com/package/react-refresh) package, as well as some custom runtime code, all of which are integrated in this plugin and can be injected through.
43
- - Code transformation can be added through loaders, such as [jsc.transform.react.refresh](https://swc.rs/docs/configuration/compilation#jsctransformreactrefresh) for [swc-loader](https://swc.rs/docs/usage/swc-loader) or the [react-refresh/babel](https://github.com/facebook/react/tree/main/packages/react-refresh) for [babel-loader](https://github.com/babel/babel-loader).
42
+ - This plugin handles runtime injection, including code from [react-refresh](https://www.npmjs.com/package/react-refresh) and the custom runtime it requires.
43
+ - Source transformation should be enabled in your loader, for example with [jsc.transform.react.refresh](https://swc.rs/docs/configuration/compilation#jsctransformreactrefresh) in [swc-loader](https://rspack.rs/guide/features/builtin-swc-loader).
44
44
 
45
45
  ```js
46
46
  import { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';
@@ -52,17 +52,15 @@ export default {
52
52
  module: {
53
53
  rules: [
54
54
  {
55
- test: /\.jsx$/,
55
+ test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
56
56
  use: {
57
57
  loader: 'builtin:swc-loader',
58
58
  options: {
59
+ detectSyntax: 'auto',
59
60
  jsc: {
60
- parser: {
61
- syntax: 'ecmascript',
62
- jsx: true,
63
- },
64
61
  transform: {
65
62
  react: {
63
+ runtime: 'automatic',
66
64
  development: isDev,
67
65
  refresh: isDev,
68
66
  },
@@ -81,8 +79,8 @@ Compared to the previous approach, this method decouples the React Fast Refresh
81
79
 
82
80
  ## Example
83
81
 
84
- - 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`.
85
- - 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)
82
+ - For usage with `builtin:swc-loader`, you can refer to the example at [examples/react-refresh](https://github.com/rstackjs/rstack-examples/blob/main/rspack/react-refresh/rspack.config.js), When using with `swc-loader`, simply replace `builtin:swc-loader` with `swc-loader`.
83
+ - For usage with `babel-loader`, you can refer to the example at [examples/react-refresh-babel-loader](https://github.com/rstackjs/rstack-examples/blob/main/rspack/react-refresh-babel-loader/rspack.config.js)
86
84
 
87
85
  ## Options
88
86
 
@@ -121,13 +119,13 @@ new ReactRefreshPlugin({
121
119
  ### exclude
122
120
 
123
121
  - Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)
124
- - Default: `/node_modules/`
122
+ - Default: `/[\\/]node_modules[\\/]/`
125
123
 
126
124
  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.
127
125
 
128
126
  ```js
129
127
  new ReactRefreshPlugin({
130
- exclude: [/node_modules/, /some-other-module/],
128
+ exclude: [/[\\/]node_modules[\\/]/, /some-other-module/],
131
129
  });
132
130
  ```
133
131
 
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ const d = (object, property, defaultValue)=>{
6
6
  };
7
7
  function normalizeOptions(options) {
8
8
  d(options, 'test', /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/);
9
- d(options, 'exclude', /node_modules/i);
9
+ d(options, 'exclude', /[\\/]node_modules[\\/]/);
10
10
  d(options, 'library');
11
11
  d(options, 'forceEnable', false);
12
12
  d(options, 'injectLoader', true);
package/dist/options.d.ts CHANGED
@@ -20,7 +20,7 @@ export type PluginOptions = {
20
20
  /**
21
21
  * Exclude files from being processed by the plugin.
22
22
  * The value is the same as the `rule.exclude` option in Rspack.
23
- * @default /node_modules/
23
+ * @default /[\\/]node_modules[\\/]/
24
24
  * @see https://rspack.rs/config/module-rules#rulesexclude
25
25
  */
26
26
  exclude?: RuleSetCondition | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/plugin-react-refresh",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "repository": "https://github.com/rstackjs/rspack-plugin-react-refresh",
5
5
  "license": "MIT",
6
6
  "description": "React refresh plugin for Rspack",
@@ -15,16 +15,6 @@
15
15
  "./react-refresh-entry": "./client/reactRefreshEntry.js",
16
16
  "./package.json": "./package.json"
17
17
  },
18
- "scripts": {
19
- "build": "rslib",
20
- "dev": "rslib -w",
21
- "lint": "rslint && prettier -c .",
22
- "lint:write": "rslint --fix && prettier -w .",
23
- "prepare": "simple-git-hooks && npm run build",
24
- "test": "rstest",
25
- "release": "node ./scripts/release.js",
26
- "bump": "npx bumpp --no-push --no-tag --no-commit"
27
- },
28
18
  "files": [
29
19
  "client",
30
20
  "dist"
@@ -33,18 +23,18 @@
33
23
  "pre-commit": "pnpm run lint:write"
34
24
  },
35
25
  "devDependencies": {
36
- "@rslib/core": "^0.20.3",
37
- "@rslint/core": "^0.3.4",
38
- "@rspack/core": "2.0.0-rc.0",
39
- "@rstest/core": "^0.9.6",
40
- "@types/node": "^24.12.2",
41
- "prettier": "^3.8.1",
26
+ "@rslib/core": "^0.22.0",
27
+ "@rslint/core": "^0.5.3",
28
+ "@rspack/core": "2.0.5",
29
+ "@rstest/core": "^0.10.3",
30
+ "@types/node": "^24.12.4",
31
+ "prettier": "^3.8.3",
42
32
  "react-refresh": "^0.18.0",
43
33
  "simple-git-hooks": "^2.13.1",
44
- "typescript": "^6.0.2"
34
+ "typescript": "^6.0.3"
45
35
  },
46
36
  "peerDependencies": {
47
- "@rspack/core": "^2.0.0-0",
37
+ "@rspack/core": "^2.0.0",
48
38
  "react-refresh": ">=0.10.0 <1.0.0"
49
39
  },
50
40
  "peerDependenciesMeta": {
@@ -52,9 +42,17 @@
52
42
  "optional": true
53
43
  }
54
44
  },
55
- "packageManager": "pnpm@10.33.0",
56
45
  "publishConfig": {
57
46
  "access": "public",
58
47
  "registry": "https://registry.npmjs.org/"
48
+ },
49
+ "scripts": {
50
+ "build": "rslib",
51
+ "dev": "rslib -w",
52
+ "lint": "rslint && prettier -c .",
53
+ "lint:write": "rslint --fix && prettier -w .",
54
+ "test": "rstest",
55
+ "release": "node ./scripts/release.js",
56
+ "bump": "npx bumpp --no-push --no-tag --no-commit"
59
57
  }
60
- }
58
+ }