@rsbuild/plugin-react 1.3.1 → 1.3.3

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
@@ -12,7 +12,7 @@ An Rsbuild plugin to provide support for React, integrating features such as JSX
12
12
 
13
13
  ## Documentation
14
14
 
15
- See [Documentation](https://rsbuild.dev/plugins/list/plugin-react).
15
+ See [Documentation](https://rsbuild.rs/plugins/list/plugin-react).
16
16
 
17
17
  ## License
18
18
 
package/dist/index.cjs CHANGED
@@ -40,93 +40,7 @@ for(var __webpack_i__ in (()=>{
40
40
  });
41
41
  let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
42
42
  var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
43
- let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
44
- let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
45
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
46
- let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
47
- return mergeEnvironmentConfig({
48
- tools: {
49
- swc: {
50
- jsc: {
51
- parser: {
52
- syntax: "typescript",
53
- tsx: !0
54
- },
55
- transform: {
56
- react: {
57
- development: isDev,
58
- refresh: usingHMR && options.fastRefresh,
59
- runtime: 'automatic',
60
- ...options.swcReactOptions
61
- }
62
- }
63
- }
64
- }
65
- }
66
- }, config);
67
- }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
68
- let { config } = environment;
69
- if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
70
- chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
71
- let { ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
72
- chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
73
- {
74
- include: [
75
- /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
76
- ],
77
- exclude: [
78
- /[\\/]node_modules[\\/]/
79
- ],
80
- ...options.reactRefreshOptions
81
- }
82
- ]);
83
- });
84
- }, applyReactProfiler = (api)=>{
85
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
86
- if ('production' === config.mode) return mergeEnvironmentConfig(config, {
87
- output: {
88
- minify: {
89
- jsOptions: {
90
- minimizerOptions: {
91
- mangle: {
92
- keep_classnames: !0,
93
- keep_fnames: !0
94
- }
95
- }
96
- }
97
- }
98
- }
99
- });
100
- }), api.modifyBundlerChain((chain, { isProd })=>{
101
- isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
102
- });
103
- }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
104
- react: !0,
105
- router: !0
106
- })=>{
107
- api.modifyBundlerChain((chain, { environment, isProd })=>{
108
- let { config } = environment;
109
- if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
110
- let currentConfig = chain.optimization.splitChunks.values();
111
- if (!isPlainObject(currentConfig)) return;
112
- let extraGroups = {};
113
- options.react && (extraGroups.react = {
114
- name: 'lib-react',
115
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
116
- priority: 0
117
- }), options.router && (extraGroups.router = {
118
- name: 'lib-router',
119
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
120
- priority: 0
121
- }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
122
- ...currentConfig,
123
- cacheGroups: {
124
- ...extraGroups,
125
- ...currentConfig.cacheGroups
126
- }
127
- });
128
- });
129
- }, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
43
+ let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
130
44
  name: PLUGIN_REACT_NAME,
131
45
  setup (api) {
132
46
  let finalOptions = {
@@ -134,7 +48,109 @@ for(var __webpack_i__ in (()=>{
134
48
  enableProfiler: !1,
135
49
  ...options
136
50
  };
137
- 'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
51
+ if ('rspack' === api.context.bundlerType) {
52
+ let hasReactDomClientCache;
53
+ var api1, api2 = api, options1 = finalOptions;
54
+ let REACT_REFRESH_PATH = options1.fastRefresh ? react_require.resolve('react-refresh') : '';
55
+ api2.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
56
+ let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
57
+ return mergeEnvironmentConfig({
58
+ tools: {
59
+ swc: {
60
+ jsc: {
61
+ parser: {
62
+ syntax: "typescript",
63
+ tsx: !0
64
+ },
65
+ transform: {
66
+ react: {
67
+ development: isDev,
68
+ refresh: usingHMR && options1.fastRefresh,
69
+ runtime: 'automatic',
70
+ ...options1.swcReactOptions
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }, config);
77
+ }), api2.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
78
+ let { config } = environment;
79
+ if (!(isDev && config.dev.hmr && 'web' === target) || !options1.fastRefresh) return;
80
+ chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
81
+ let { ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
82
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
83
+ {
84
+ include: [
85
+ /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
86
+ ],
87
+ exclude: [
88
+ /[\\/]node_modules[\\/]/
89
+ ],
90
+ resourceQuery: {
91
+ not: /raw/
92
+ },
93
+ ...options1.reactRefreshOptions
94
+ }
95
+ ]);
96
+ }), finalOptions.enableProfiler && ((api1 = api).modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
97
+ if ('production' === config.mode) return mergeEnvironmentConfig(config, {
98
+ output: {
99
+ minify: {
100
+ jsOptions: {
101
+ minimizerOptions: {
102
+ mangle: {
103
+ keep_classnames: !0,
104
+ keep_fnames: !0
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ });
111
+ }), api1.modifyBundlerChain((chain, { isProd })=>{
112
+ isProd && (chain.resolve.alias.set((()=>{
113
+ if (void 0 !== hasReactDomClientCache) return hasReactDomClientCache;
114
+ try {
115
+ react_require.resolve('react-dom/client', {
116
+ paths: [
117
+ api1.context.rootPath
118
+ ]
119
+ }), hasReactDomClientCache = !0;
120
+ } catch {
121
+ hasReactDomClientCache = !1;
122
+ }
123
+ return hasReactDomClientCache;
124
+ })() ? 'react-dom/client$' : 'react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
125
+ }));
126
+ }
127
+ ((api, options = {
128
+ react: !0,
129
+ router: !0
130
+ })=>{
131
+ api.modifyBundlerChain((chain, { environment, isProd })=>{
132
+ let obj, { config } = environment;
133
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
134
+ let currentConfig = chain.optimization.splitChunks.values();
135
+ if (null === (obj = currentConfig) || 'object' != typeof obj || '[object Object]' !== Object.prototype.toString.call(obj)) return;
136
+ let extraGroups = {};
137
+ options.react && (extraGroups.react = {
138
+ name: 'lib-react',
139
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
140
+ priority: 0
141
+ }), options.router && (extraGroups.router = {
142
+ name: 'lib-router',
143
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
144
+ priority: 0
145
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
146
+ ...currentConfig,
147
+ cacheGroups: {
148
+ ...extraGroups,
149
+ ...currentConfig.cacheGroups
150
+ }
151
+ });
152
+ });
153
+ })(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
138
154
  }
139
155
  });
140
156
  })(), exports.PLUGIN_REACT_NAME = __webpack_exports__.PLUGIN_REACT_NAME, exports.pluginReact = __webpack_exports__.pluginReact, __webpack_exports__)-1 === [
package/dist/index.d.ts CHANGED
@@ -31,7 +31,13 @@ export type PluginReactOptions = {
31
31
  enableProfiler?: boolean;
32
32
  /**
33
33
  * Options passed to `@rspack/plugin-react-refresh`
34
- * @see https://rspack.dev/guide/tech/react#rspackplugin-react-refresh
34
+ * @default
35
+ * {
36
+ * include: [/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/],
37
+ * exclude: [/[\\/]node_modules[\\/]/],
38
+ * resourceQuery: { not: /raw/ },
39
+ * }
40
+ * @see https://rspack.rs/guide/tech/react#rspackplugin-react-refresh
35
41
  */
36
42
  reactRefreshOptions?: ReactRefreshOptions;
37
43
  /**
package/dist/index.js CHANGED
@@ -1,92 +1,6 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
2
- import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
3
- let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), applyBasicReactSupport = (api, options)=>{
4
- let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
5
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
6
- let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
7
- return mergeEnvironmentConfig({
8
- tools: {
9
- swc: {
10
- jsc: {
11
- parser: {
12
- syntax: "typescript",
13
- tsx: !0
14
- },
15
- transform: {
16
- react: {
17
- development: isDev,
18
- refresh: usingHMR && options.fastRefresh,
19
- runtime: 'automatic',
20
- ...options.swcReactOptions
21
- }
22
- }
23
- }
24
- }
25
- }
26
- }, config);
27
- }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
28
- let { config } = environment;
29
- if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
30
- chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(REACT_REFRESH_PATH));
31
- let { ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
32
- chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
33
- {
34
- include: [
35
- /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
36
- ],
37
- exclude: [
38
- /[\\/]node_modules[\\/]/
39
- ],
40
- ...options.reactRefreshOptions
41
- }
42
- ]);
43
- });
44
- }, applyReactProfiler = (api)=>{
45
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
46
- if ('production' === config.mode) return mergeEnvironmentConfig(config, {
47
- output: {
48
- minify: {
49
- jsOptions: {
50
- minimizerOptions: {
51
- mangle: {
52
- keep_classnames: !0,
53
- keep_fnames: !0
54
- }
55
- }
56
- }
57
- }
58
- }
59
- });
60
- }), api.modifyBundlerChain((chain, { isProd })=>{
61
- isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
62
- });
63
- }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
64
- react: !0,
65
- router: !0
66
- })=>{
67
- api.modifyBundlerChain((chain, { environment, isProd })=>{
68
- let { config } = environment;
69
- if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
70
- let currentConfig = chain.optimization.splitChunks.values();
71
- if (!isPlainObject(currentConfig)) return;
72
- let extraGroups = {};
73
- options.react && (extraGroups.react = {
74
- name: 'lib-react',
75
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
76
- priority: 0
77
- }), options.router && (extraGroups.router = {
78
- name: 'lib-router',
79
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
80
- priority: 0
81
- }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
82
- ...currentConfig,
83
- cacheGroups: {
84
- ...extraGroups,
85
- ...currentConfig.cacheGroups
86
- }
87
- });
88
- });
89
- }, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
1
+ import { createRequire } from "node:module";
2
+ import node_path from "node:path";
3
+ let react_require = createRequire(import.meta.url), PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
90
4
  name: PLUGIN_REACT_NAME,
91
5
  setup (api) {
92
6
  let finalOptions = {
@@ -94,7 +8,107 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createR
94
8
  enableProfiler: !1,
95
9
  ...options
96
10
  };
97
- 'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
11
+ if ('rspack' === api.context.bundlerType) {
12
+ let hasReactDomClientCache, REACT_REFRESH_PATH = finalOptions.fastRefresh ? react_require.resolve('react-refresh') : '';
13
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
14
+ let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
15
+ return mergeEnvironmentConfig({
16
+ tools: {
17
+ swc: {
18
+ jsc: {
19
+ parser: {
20
+ syntax: "typescript",
21
+ tsx: !0
22
+ },
23
+ transform: {
24
+ react: {
25
+ development: isDev,
26
+ refresh: usingHMR && finalOptions.fastRefresh,
27
+ runtime: 'automatic',
28
+ ...finalOptions.swcReactOptions
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }, config);
35
+ }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
36
+ let { config } = environment;
37
+ if (!(isDev && config.dev.hmr && 'web' === target) || !finalOptions.fastRefresh) return;
38
+ chain.resolve.alias.set('react-refresh', node_path.dirname(REACT_REFRESH_PATH));
39
+ let { ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
40
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
41
+ {
42
+ include: [
43
+ /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
44
+ ],
45
+ exclude: [
46
+ /[\\/]node_modules[\\/]/
47
+ ],
48
+ resourceQuery: {
49
+ not: /raw/
50
+ },
51
+ ...finalOptions.reactRefreshOptions
52
+ }
53
+ ]);
54
+ }), finalOptions.enableProfiler && (api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
55
+ if ('production' === config.mode) return mergeEnvironmentConfig(config, {
56
+ output: {
57
+ minify: {
58
+ jsOptions: {
59
+ minimizerOptions: {
60
+ mangle: {
61
+ keep_classnames: !0,
62
+ keep_fnames: !0
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ });
69
+ }), api.modifyBundlerChain((chain, { isProd })=>{
70
+ isProd && (chain.resolve.alias.set((()=>{
71
+ if (void 0 !== hasReactDomClientCache) return hasReactDomClientCache;
72
+ try {
73
+ react_require.resolve('react-dom/client', {
74
+ paths: [
75
+ api.context.rootPath
76
+ ]
77
+ }), hasReactDomClientCache = !0;
78
+ } catch {
79
+ hasReactDomClientCache = !1;
80
+ }
81
+ return hasReactDomClientCache;
82
+ })() ? 'react-dom/client$' : 'react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
83
+ }));
84
+ }
85
+ ((api, options = {
86
+ react: !0,
87
+ router: !0
88
+ })=>{
89
+ api.modifyBundlerChain((chain, { environment, isProd })=>{
90
+ let { config } = environment;
91
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
92
+ let currentConfig = chain.optimization.splitChunks.values();
93
+ if (null === currentConfig || 'object' != typeof currentConfig || '[object Object]' !== Object.prototype.toString.call(currentConfig)) return;
94
+ let extraGroups = {};
95
+ options.react && (extraGroups.react = {
96
+ name: 'lib-react',
97
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
98
+ priority: 0
99
+ }), options.router && (extraGroups.router = {
100
+ name: 'lib-router',
101
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
102
+ priority: 0
103
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
104
+ ...currentConfig,
105
+ cacheGroups: {
106
+ ...extraGroups,
107
+ ...currentConfig.cacheGroups
108
+ }
109
+ });
110
+ });
111
+ })(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
98
112
  }
99
113
  });
100
114
  export { PLUGIN_REACT_NAME, pluginReact };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,14 +22,14 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rspack/plugin-react-refresh": "~1.4.2",
25
+ "@rspack/plugin-react-refresh": "~1.4.3",
26
26
  "react-refresh": "^0.17.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@rslib/core": "0.6.8",
30
- "@types/node": "^22.15.3",
29
+ "@rslib/core": "0.10.4",
30
+ "@types/node": "^22.15.34",
31
31
  "typescript": "^5.8.3",
32
- "@rsbuild/core": "1.3.16",
32
+ "@rsbuild/core": "1.4.3",
33
33
  "@scripts/test-helper": "1.0.1"
34
34
  },
35
35
  "peerDependencies": {
@@ -42,6 +42,7 @@
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rslib build",
45
- "dev": "rslib build --watch"
45
+ "dev": "rslib build --watch",
46
+ "bump": "npx bumpp --no-tag"
46
47
  }
47
48
  }