@rsbuild/plugin-react 1.1.0 → 1.1.1

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,19 +1,19 @@
1
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
3
- </p>
1
+ # @rsbuild/plugin-react
4
2
 
5
- # Rsbuild
3
+ An Rsbuild plugin to provide support for React, integrating features such as JSX compilation and React Refresh.
6
4
 
7
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
5
+ <p>
6
+ <a href="https://npmjs.com/package/@rsbuild/plugin-react">
7
+ <img src="https://img.shields.io/npm/v/@rsbuild/plugin-react?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
8
+ </a>
9
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10
+ <a href="https://npmcharts.com/compare/@rsbuild/plugin-react?minimal=true"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-react.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
11
+ </p>
8
12
 
9
13
  ## Documentation
10
14
 
11
- https://rsbuild.dev/
12
-
13
- ## Contributing
14
-
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
15
+ See [Documentation](https://rsbuild.dev/plugins/list/plugin-react).
16
16
 
17
17
  ## License
18
18
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
19
+ [MIT](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
package/dist/index.cjs CHANGED
@@ -37,109 +37,111 @@ __webpack_require__.n = function(module) {
37
37
  });
38
38
  };
39
39
  var __webpack_exports__ = {};
40
- __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
41
- PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME,
42
- pluginReact: ()=>pluginReact
43
- });
44
- let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
45
- var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
46
- let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
47
- let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
48
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
49
- let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target, reactOptions = {
50
- development: isDev,
51
- refresh: usingHMR && options.fastRefresh,
52
- runtime: 'automatic',
53
- ...options.swcReactOptions
54
- };
55
- return mergeEnvironmentConfig({
56
- tools: {
57
- swc: {
58
- jsc: {
59
- parser: {
60
- syntax: 'typescript',
61
- tsx: !0
62
- },
63
- transform: {
64
- react: reactOptions
40
+ (()=>{
41
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
42
+ pluginReact: ()=>pluginReact,
43
+ PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME
44
+ });
45
+ let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
46
+ var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
47
+ let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
48
+ let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
49
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
50
+ let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
51
+ return mergeEnvironmentConfig({
52
+ tools: {
53
+ swc: {
54
+ jsc: {
55
+ parser: {
56
+ syntax: "typescript",
57
+ tsx: !0
58
+ },
59
+ transform: {
60
+ react: {
61
+ development: isDev,
62
+ refresh: usingHMR && options.fastRefresh,
63
+ runtime: 'automatic',
64
+ ...options.swcReactOptions
65
+ }
66
+ }
65
67
  }
66
68
  }
67
69
  }
68
- }
69
- }, config);
70
- }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
71
- let { config } = environment;
72
- if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
73
- chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
74
- let { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
75
- chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
76
- {
77
- include: [
78
- /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
79
- ],
80
- exclude: [
81
- /[\\/]node_modules[\\/]/
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
70
+ }, config);
71
+ }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
72
+ let { config } = environment;
73
+ if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
74
+ chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
75
+ let { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
76
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
77
+ {
78
+ include: [
79
+ /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
80
+ ],
81
+ exclude: [
82
+ /[\\/]node_modules[\\/]/
83
+ ],
84
+ ...options.reactRefreshOptions
85
+ }
86
+ ]);
87
+ });
88
+ }, applyReactProfiler = (api)=>{
89
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
90
+ if ('production' === config.mode) return mergeEnvironmentConfig(config, {
91
+ output: {
92
+ minify: {
93
+ jsOptions: {
94
+ minimizerOptions: {
95
+ mangle: {
96
+ keep_classnames: !0,
97
+ keep_fnames: !0
98
+ }
97
99
  }
98
100
  }
99
101
  }
100
102
  }
101
- }
103
+ });
104
+ }), api.modifyBundlerChain((chain, { isProd })=>{
105
+ isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
102
106
  });
103
- }), api.modifyBundlerChain((chain, { isProd })=>{
104
- if (!!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
- if (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
107
+ }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
108
+ react: !0,
109
+ router: !0
110
+ })=>{
111
+ api.modifyBundlerChain((chain, { environment, isProd })=>{
112
+ let { config } = environment;
113
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
114
+ let currentConfig = chain.optimization.splitChunks.values();
115
+ if (!isPlainObject(currentConfig)) return;
116
+ let extraGroups = {};
117
+ options.react && (extraGroups.react = {
118
+ name: 'lib-react',
119
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
120
+ priority: 0
121
+ }), options.router && (extraGroups.router = {
122
+ name: 'lib-router',
123
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
124
+ priority: 0
125
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
126
+ ...currentConfig,
127
+ cacheGroups: {
128
+ ...extraGroups,
129
+ ...currentConfig.cacheGroups
130
+ }
131
+ });
132
+ });
133
+ }, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
134
+ name: PLUGIN_REACT_NAME,
135
+ setup (api) {
136
+ let finalOptions = {
137
+ fastRefresh: !0,
138
+ enableProfiler: !1,
139
+ ...options
140
+ };
141
+ 'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
129
142
  }
130
143
  });
131
- });
132
- }, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
133
- name: PLUGIN_REACT_NAME,
134
- setup (api) {
135
- let finalOptions = {
136
- fastRefresh: !0,
137
- enableProfiler: !1,
138
- ...options
139
- };
140
- 'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
141
- }
142
- });
144
+ })();
143
145
  var __webpack_export_target__ = exports;
144
146
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
145
147
  __webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
2
- import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
3
- let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url), applyBasicReactSupport = (api, options)=>{
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
4
  let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
5
5
  api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
6
- let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target, reactOptions = {
7
- development: isDev,
8
- refresh: usingHMR && options.fastRefresh,
9
- runtime: 'automatic',
10
- ...options.swcReactOptions
11
- };
6
+ let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
12
7
  return mergeEnvironmentConfig({
13
8
  tools: {
14
9
  swc: {
15
10
  jsc: {
16
11
  parser: {
17
- syntax: 'typescript',
12
+ syntax: "typescript",
18
13
  tsx: !0
19
14
  },
20
15
  transform: {
21
- react: reactOptions
16
+ react: {
17
+ development: isDev,
18
+ refresh: usingHMR && options.fastRefresh,
19
+ runtime: 'automatic',
20
+ ...options.swcReactOptions
21
+ }
22
22
  }
23
23
  }
24
24
  }
@@ -27,7 +27,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
27
27
  }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
28
28
  let { config } = environment;
29
29
  if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
30
- chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path__.default.dirname(REACT_REFRESH_PATH));
30
+ chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(REACT_REFRESH_PATH));
31
31
  let { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
32
32
  chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
33
33
  {
@@ -58,7 +58,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
58
58
  }
59
59
  });
60
60
  }), api.modifyBundlerChain((chain, { isProd })=>{
61
- if (!!isProd) chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
61
+ isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
62
62
  });
63
63
  }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
64
64
  react: !0,
@@ -70,7 +70,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
70
70
  let currentConfig = chain.optimization.splitChunks.values();
71
71
  if (!isPlainObject(currentConfig)) return;
72
72
  let extraGroups = {};
73
- if (options.react && (extraGroups.react = {
73
+ options.react && (extraGroups.react = {
74
74
  name: 'lib-react',
75
75
  test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
76
76
  priority: 0
@@ -78,7 +78,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
78
78
  name: 'lib-router',
79
79
  test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
80
80
  priority: 0
81
- }), !!Object.keys(extraGroups).length) chain.optimization.splitChunks({
81
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
82
82
  ...currentConfig,
83
83
  cacheGroups: {
84
84
  ...extraGroups,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,15 +22,15 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rspack/plugin-react-refresh": "~1.0.0",
25
+ "@rspack/plugin-react-refresh": "~1.0.1",
26
26
  "react-refresh": "^0.16.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@rslib/core": "0.1.3",
30
- "@types/node": "^22.10.1",
31
- "typescript": "^5.7.2",
32
- "@rsbuild/core": "1.1.9",
33
- "@scripts/test-helper": "1.0.1"
29
+ "@rslib/core": "0.4.1",
30
+ "@types/node": "^22.13.4",
31
+ "typescript": "^5.7.3",
32
+ "@scripts/test-helper": "1.0.1",
33
+ "@rsbuild/core": "1.2.9"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@rsbuild/core": "1.x"