@rsbuild/plugin-react 1.1.0 → 1.2.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,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
@@ -13,23 +13,17 @@ function __webpack_require__(moduleId) {
13
13
  };
14
14
  return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
15
15
  }
16
- __webpack_require__.n = function(module) {
17
- var getter = module && module.__esModule ? function() {
18
- return module.default;
19
- } : function() {
20
- return module;
21
- };
16
+ __webpack_require__.n = (module)=>{
17
+ var getter = module && module.__esModule ? ()=>module.default : ()=>module;
22
18
  return __webpack_require__.d(getter, {
23
19
  a: getter
24
20
  }), getter;
25
- }, __webpack_require__.d = function(exports1, definition) {
21
+ }, __webpack_require__.d = (exports1, definition)=>{
26
22
  for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
27
23
  enumerable: !0,
28
24
  get: definition[key]
29
25
  });
30
- }, __webpack_require__.o = function(obj, prop) {
31
- return Object.prototype.hasOwnProperty.call(obj, prop);
32
- }, __webpack_require__.r = function(exports1) {
26
+ }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
33
27
  'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
34
28
  value: 'Module'
35
29
  }), Object.defineProperty(exports1, '__esModule', {
@@ -37,111 +31,114 @@ __webpack_require__.n = function(module) {
37
31
  });
38
32
  };
39
33
  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
34
+ for(var __webpack_i__ in (()=>{
35
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
36
+ PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME,
37
+ pluginReact: ()=>pluginReact
38
+ });
39
+ let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
40
+ var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
41
+ let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
42
+ let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
43
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
44
+ let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
45
+ return mergeEnvironmentConfig({
46
+ tools: {
47
+ swc: {
48
+ jsc: {
49
+ parser: {
50
+ syntax: "typescript",
51
+ tsx: !0
52
+ },
53
+ transform: {
54
+ react: {
55
+ development: isDev,
56
+ refresh: usingHMR && options.fastRefresh,
57
+ runtime: 'automatic',
58
+ ...options.swcReactOptions
59
+ }
60
+ }
65
61
  }
66
62
  }
67
63
  }
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
64
+ }, config);
65
+ }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
66
+ let { config } = environment;
67
+ if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
68
+ chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
69
+ let { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
70
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
71
+ {
72
+ include: [
73
+ /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
74
+ ],
75
+ exclude: [
76
+ /[\\/]node_modules[\\/]/
77
+ ],
78
+ ...options.reactRefreshOptions
79
+ }
80
+ ]);
81
+ });
82
+ }, applyReactProfiler = (api)=>{
83
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
84
+ if ('production' === config.mode) return mergeEnvironmentConfig(config, {
85
+ output: {
86
+ minify: {
87
+ jsOptions: {
88
+ minimizerOptions: {
89
+ mangle: {
90
+ keep_classnames: !0,
91
+ keep_fnames: !0
92
+ }
97
93
  }
98
94
  }
99
95
  }
100
96
  }
101
- }
97
+ });
98
+ }), api.modifyBundlerChain((chain, { isProd })=>{
99
+ isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
102
100
  });
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
101
+ }, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
102
+ react: !0,
103
+ router: !0
104
+ })=>{
105
+ api.modifyBundlerChain((chain, { environment, isProd })=>{
106
+ let { config } = environment;
107
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
108
+ let currentConfig = chain.optimization.splitChunks.values();
109
+ if (!isPlainObject(currentConfig)) return;
110
+ let extraGroups = {};
111
+ options.react && (extraGroups.react = {
112
+ name: 'lib-react',
113
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
114
+ priority: 0
115
+ }), options.router && (extraGroups.router = {
116
+ name: 'lib-router',
117
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
118
+ priority: 0
119
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
120
+ ...currentConfig,
121
+ cacheGroups: {
122
+ ...extraGroups,
123
+ ...currentConfig.cacheGroups
124
+ }
125
+ });
126
+ });
127
+ }, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
128
+ name: PLUGIN_REACT_NAME,
129
+ setup (api) {
130
+ let finalOptions = {
131
+ fastRefresh: !0,
132
+ enableProfiler: !1,
133
+ ...options
134
+ };
135
+ 'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
129
136
  }
130
137
  });
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
- });
143
- var __webpack_export_target__ = exports;
144
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
145
- __webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
138
+ })(), exports.PLUGIN_REACT_NAME = __webpack_exports__.PLUGIN_REACT_NAME, exports.pluginReact = __webpack_exports__.pluginReact, __webpack_exports__)-1 === [
139
+ "PLUGIN_REACT_NAME",
140
+ "pluginReact"
141
+ ].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
142
+ Object.defineProperty(exports, '__esModule', {
146
143
  value: !0
147
144
  });
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.2.0",
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.0.0",
26
- "react-refresh": "^0.16.0"
25
+ "@rspack/plugin-react-refresh": "~1.2.0",
26
+ "react-refresh": "^0.17.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",
29
+ "@rslib/core": "0.6.1",
30
+ "@types/node": "^22.14.0",
31
+ "typescript": "^5.8.3",
32
+ "@rsbuild/core": "1.3.5",
33
33
  "@scripts/test-helper": "1.0.1"
34
34
  },
35
35
  "peerDependencies": {