@rsbuild/plugin-react 1.3.2 → 1.3.4

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/dist/index.cjs CHANGED
@@ -40,96 +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
- resourceQuery: {
81
- not: /raw/
82
- },
83
- ...options.reactRefreshOptions
84
- }
85
- ]);
86
- });
87
- }, applyReactProfiler = (api)=>{
88
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
89
- if ('production' === config.mode) return mergeEnvironmentConfig(config, {
90
- output: {
91
- minify: {
92
- jsOptions: {
93
- minimizerOptions: {
94
- mangle: {
95
- keep_classnames: !0,
96
- keep_fnames: !0
97
- }
98
- }
99
- }
100
- }
101
- }
102
- });
103
- }), api.modifyBundlerChain((chain, { isProd })=>{
104
- isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
105
- });
106
- }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
107
- react: !0,
108
- router: !0
109
- })=>{
110
- api.modifyBundlerChain((chain, { environment, isProd })=>{
111
- let { config } = environment;
112
- if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
113
- let currentConfig = chain.optimization.splitChunks.values();
114
- if (!isPlainObject(currentConfig)) return;
115
- let extraGroups = {};
116
- options.react && (extraGroups.react = {
117
- name: 'lib-react',
118
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
119
- priority: 0
120
- }), options.router && (extraGroups.router = {
121
- name: 'lib-router',
122
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
123
- priority: 0
124
- }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
125
- ...currentConfig,
126
- cacheGroups: {
127
- ...extraGroups,
128
- ...currentConfig.cacheGroups
129
- }
130
- });
131
- });
132
- }, 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 = {})=>({
133
44
  name: PLUGIN_REACT_NAME,
134
45
  setup (api) {
135
46
  let finalOptions = {
@@ -137,7 +48,109 @@ for(var __webpack_i__ in (()=>{
137
48
  enableProfiler: !1,
138
49
  ...options
139
50
  };
140
- '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);
141
154
  }
142
155
  });
143
156
  })(), exports.PLUGIN_REACT_NAME = __webpack_exports__.PLUGIN_REACT_NAME, exports.pluginReact = __webpack_exports__.pluginReact, __webpack_exports__)-1 === [
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@ export type PluginReactOptions = {
35
35
  * {
36
36
  * include: [/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/],
37
37
  * exclude: [/[\\/]node_modules[\\/]/],
38
- * resourceQuery: { not: /raw/ },
38
+ * resourceQuery: { not: /^\?raw$/ },
39
39
  * }
40
40
  * @see https://rspack.rs/guide/tech/react#rspackplugin-react-refresh
41
41
  */
package/dist/index.js CHANGED
@@ -1,95 +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
- resourceQuery: {
41
- not: /raw/
42
- },
43
- ...options.reactRefreshOptions
44
- }
45
- ]);
46
- });
47
- }, applyReactProfiler = (api)=>{
48
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
49
- if ('production' === config.mode) return mergeEnvironmentConfig(config, {
50
- output: {
51
- minify: {
52
- jsOptions: {
53
- minimizerOptions: {
54
- mangle: {
55
- keep_classnames: !0,
56
- keep_fnames: !0
57
- }
58
- }
59
- }
60
- }
61
- }
62
- });
63
- }), api.modifyBundlerChain((chain, { isProd })=>{
64
- isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
65
- });
66
- }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
67
- react: !0,
68
- router: !0
69
- })=>{
70
- api.modifyBundlerChain((chain, { environment, isProd })=>{
71
- let { config } = environment;
72
- if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
73
- let currentConfig = chain.optimization.splitChunks.values();
74
- if (!isPlainObject(currentConfig)) return;
75
- let extraGroups = {};
76
- options.react && (extraGroups.react = {
77
- name: 'lib-react',
78
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
79
- priority: 0
80
- }), options.router && (extraGroups.router = {
81
- name: 'lib-router',
82
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
83
- priority: 0
84
- }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
85
- ...currentConfig,
86
- cacheGroups: {
87
- ...extraGroups,
88
- ...currentConfig.cacheGroups
89
- }
90
- });
91
- });
92
- }, 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 = {})=>({
93
4
  name: PLUGIN_REACT_NAME,
94
5
  setup (api) {
95
6
  let finalOptions = {
@@ -97,7 +8,107 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createR
97
8
  enableProfiler: !1,
98
9
  ...options
99
10
  };
100
- '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);
101
112
  }
102
113
  });
103
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.2",
3
+ "version": "1.3.4",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,11 +26,11 @@
26
26
  "react-refresh": "^0.17.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@rslib/core": "0.9.1",
30
- "@types/node": "^22.15.29",
29
+ "@rslib/core": "0.10.4",
30
+ "@types/node": "^22.16.0",
31
31
  "typescript": "^5.8.3",
32
- "@rsbuild/core": "1.4.0-beta.0",
33
- "@scripts/test-helper": "1.0.1"
32
+ "@scripts/test-helper": "1.0.1",
33
+ "@rsbuild/core": "1.4.4"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@rsbuild/core": "1.x"