@rsbuild/plugin-react 1.0.3 → 1.0.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
@@ -1,187 +1,253 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
2
+ var __webpack_modules__ = {
3
+ "@rspack/plugin-react-refresh": function(module1) {
4
+ module1.exports = require("@rspack/plugin-react-refresh");
5
+ }
19
6
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- PLUGIN_REACT_NAME: () => PLUGIN_REACT_NAME,
34
- pluginReact: () => pluginReact
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
- // src/react.ts
39
- var import_node_path = __toESM(require("path"));
40
- var applyBasicReactSupport = (api, options) => {
41
- const REACT_REFRESH_PATH = require.resolve("react-refresh");
42
- api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig }) => {
43
- const isDev = userConfig.mode === "development";
44
- const reactOptions = {
45
- development: isDev,
46
- refresh: isDev && userConfig.dev.hmr && userConfig.output.target === "web",
47
- runtime: "automatic",
48
- ...options.swcReactOptions
7
+ /************************************************************************/ // The module cache
8
+ var __webpack_module_cache__ = {};
9
+ // The require function
10
+ function __webpack_require__(moduleId) {
11
+ // Check if module is in cache
12
+ var cachedModule = __webpack_module_cache__[moduleId];
13
+ if (void 0 !== cachedModule) return cachedModule.exports;
14
+ // Create a new module (and put it into the cache)
15
+ var module1 = __webpack_module_cache__[moduleId] = {
16
+ exports: {}
49
17
  };
50
- const extraConfig = {
51
- tools: {
52
- swc: {
53
- jsc: {
54
- parser: {
55
- syntax: "typescript",
56
- // enable supports for JSX/TSX compilation
57
- tsx: true
58
- },
59
- transform: {
60
- react: reactOptions
61
- }
62
- }
63
- }
64
- }
18
+ // Execute the module function
19
+ __webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
20
+ // Return the exports of the module
21
+ return module1.exports;
22
+ }
23
+ /************************************************************************/ // webpack/runtime/compat_get_default_export
24
+ (()=>{
25
+ // getDefaultExport function for compatibility with non-harmony modules
26
+ __webpack_require__.n = function(module1) {
27
+ var getter = module1 && module1.__esModule ? function() {
28
+ return module1['default'];
29
+ } : function() {
30
+ return module1;
31
+ };
32
+ __webpack_require__.d(getter, {
33
+ a: getter
34
+ });
35
+ return getter;
65
36
  };
66
- return mergeEnvironmentConfig(extraConfig, userConfig);
67
- });
68
- api.modifyBundlerChain(
69
- async (chain, { CHAIN_ID, environment, isDev, target }) => {
70
- const { config } = environment;
71
- const usingHMR = isDev && config.dev.hmr && target === "web";
72
- if (!usingHMR) {
73
- return;
74
- }
75
- chain.resolve.alias.set(
76
- "react-refresh",
77
- import_node_path.default.dirname(REACT_REFRESH_PATH)
78
- );
79
- const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
80
- const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
81
- const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
82
- chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
83
- {
84
- include: [SCRIPT_REGEX],
85
- exclude: [NODE_MODULES_REGEX],
86
- ...options.reactRefreshOptions
37
+ })();
38
+ // webpack/runtime/create_fake_namespace_object
39
+ (()=>{
40
+ var getProto = Object.getPrototypeOf ? function(obj) {
41
+ return Object.getPrototypeOf(obj);
42
+ } : function(obj) {
43
+ return obj.__proto__;
44
+ };
45
+ var leafPrototypes;
46
+ // create a fake namespace object
47
+ // mode & 1: value is a module id, require it
48
+ // mode & 2: merge all properties of value into the ns
49
+ // mode & 4: return value when already ns object
50
+ // mode & 16: return value when it's Promise-like
51
+ // mode & 8|1: behave like require
52
+ __webpack_require__.t = function(value, mode) {
53
+ if (1 & mode) value = this(value);
54
+ if (8 & mode) return value;
55
+ if ('object' == typeof value && value) {
56
+ if (4 & mode && value.__esModule) return value;
57
+ if (16 & mode && 'function' == typeof value.then) return value;
87
58
  }
88
- ]);
89
- }
90
- );
59
+ var ns = Object.create(null);
60
+ __webpack_require__.r(ns);
61
+ var def = {};
62
+ leafPrototypes = leafPrototypes || [
63
+ null,
64
+ getProto({}),
65
+ getProto([]),
66
+ getProto(getProto)
67
+ ];
68
+ for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
69
+ def[key] = function() {
70
+ return value[key];
71
+ };
72
+ });
73
+ def['default'] = function() {
74
+ return value;
75
+ };
76
+ __webpack_require__.d(ns, def);
77
+ return ns;
78
+ };
79
+ })();
80
+ // webpack/runtime/define_property_getters
81
+ (()=>{
82
+ __webpack_require__.d = function(exports1, definition) {
83
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
84
+ enumerable: true,
85
+ get: definition[key]
86
+ });
87
+ };
88
+ })();
89
+ // webpack/runtime/has_own_property
90
+ (()=>{
91
+ __webpack_require__.o = function(obj, prop) {
92
+ return Object.prototype.hasOwnProperty.call(obj, prop);
93
+ };
94
+ })();
95
+ // webpack/runtime/make_namespace_object
96
+ (()=>{
97
+ // define __esModule on exports
98
+ __webpack_require__.r = function(exports1) {
99
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
100
+ value: 'Module'
101
+ });
102
+ Object.defineProperty(exports1, '__esModule', {
103
+ value: true
104
+ });
105
+ };
106
+ })();
107
+ /************************************************************************/ var __webpack_exports__ = {};
108
+ // ESM COMPAT FLAG
109
+ __webpack_require__.r(__webpack_exports__);
110
+ // EXPORTS
111
+ __webpack_require__.d(__webpack_exports__, {
112
+ PLUGIN_REACT_NAME: ()=>/* binding */ PLUGIN_REACT_NAME,
113
+ pluginReact: ()=>/* binding */ pluginReact
114
+ });
115
+ const external_node_module_namespaceObject = require("node:module");
116
+ const external_node_path_namespaceObject = require("node:path");
117
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
118
+ const react_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
119
+ return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
120
+ }());
121
+ const applyBasicReactSupport = (api, options)=>{
122
+ const REACT_REFRESH_PATH = react_require.resolve('react-refresh');
123
+ api.modifyEnvironmentConfig((userConfig, param)=>{
124
+ let { mergeEnvironmentConfig } = param;
125
+ const isDev = 'development' === userConfig.mode;
126
+ const reactOptions = {
127
+ development: isDev,
128
+ refresh: isDev && userConfig.dev.hmr && 'web' === userConfig.output.target,
129
+ runtime: 'automatic',
130
+ ...options.swcReactOptions
131
+ };
132
+ const extraConfig = {
133
+ tools: {
134
+ swc: {
135
+ jsc: {
136
+ parser: {
137
+ syntax: 'typescript',
138
+ // enable supports for JSX/TSX compilation
139
+ tsx: true
140
+ },
141
+ transform: {
142
+ react: reactOptions
143
+ }
144
+ }
145
+ }
146
+ }
147
+ };
148
+ return mergeEnvironmentConfig(extraConfig, userConfig);
149
+ });
150
+ api.modifyBundlerChain(async (chain, param)=>{
151
+ let { CHAIN_ID, environment, isDev, target } = param;
152
+ const { config } = environment;
153
+ const usingHMR = isDev && config.dev.hmr && 'web' === target;
154
+ if (!usingHMR) return;
155
+ chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
156
+ const { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "@rspack/plugin-react-refresh", 23));
157
+ const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
158
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
159
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
160
+ {
161
+ include: [
162
+ SCRIPT_REGEX
163
+ ],
164
+ exclude: [
165
+ NODE_MODULES_REGEX
166
+ ],
167
+ ...options.reactRefreshOptions
168
+ }
169
+ ]);
170
+ });
91
171
  };
92
- var applyReactProfiler = (api) => {
93
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig }) => {
94
- if (config.mode !== "production") {
95
- return;
96
- }
97
- const enableProfilerConfig = {
98
- output: {
99
- minify: {
100
- jsOptions: {
101
- minimizerOptions: {
102
- // Need to keep classnames and function names like Components for debugging purposes.
103
- mangle: {
104
- keep_classnames: true,
105
- keep_fnames: true
106
- }
172
+ const applyReactProfiler = (api)=>{
173
+ api.modifyEnvironmentConfig((config, param)=>{
174
+ let { mergeEnvironmentConfig } = param;
175
+ if ('production' !== config.mode) return;
176
+ const enableProfilerConfig = {
177
+ output: {
178
+ minify: {
179
+ jsOptions: {
180
+ minimizerOptions: {
181
+ // Need to keep classnames and function names like Components for debugging purposes.
182
+ mangle: {
183
+ keep_classnames: true,
184
+ keep_fnames: true
185
+ }
186
+ }
187
+ }
188
+ }
107
189
  }
108
- }
109
- }
110
- }
111
- };
112
- return mergeEnvironmentConfig(config, enableProfilerConfig);
113
- });
114
- api.modifyBundlerChain((chain, { isProd }) => {
115
- if (!isProd) {
116
- return;
117
- }
118
- chain.resolve.alias.set("react-dom$", "react-dom/profiling");
119
- chain.resolve.alias.set("scheduler/tracing", "scheduler/tracing-profiling");
120
- });
190
+ };
191
+ return mergeEnvironmentConfig(config, enableProfilerConfig);
192
+ });
193
+ api.modifyBundlerChain((chain, param)=>{
194
+ let { isProd } = param;
195
+ if (!isProd) return;
196
+ // Replace react-dom with the profiling version.
197
+ // Reference: https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977
198
+ chain.resolve.alias.set('react-dom$', 'react-dom/profiling');
199
+ chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
200
+ });
121
201
  };
122
-
123
- // src/splitChunks.ts
124
- var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
125
- var applySplitChunksRule = (api, options = {
126
- react: true,
127
- router: true
128
- }) => {
129
- api.modifyBundlerChain((chain, { environment, isProd }) => {
130
- const { config } = environment;
131
- if (config.performance.chunkSplit.strategy !== "split-by-experience") {
132
- return;
133
- }
134
- const currentConfig = chain.optimization.splitChunks.values();
135
- if (!isPlainObject(currentConfig)) {
136
- return;
137
- }
138
- const extraGroups = {};
139
- if (options.react) {
140
- extraGroups.react = {
141
- name: "lib-react",
142
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
143
- priority: 0
144
- };
145
- }
146
- if (options.router) {
147
- extraGroups.router = {
148
- name: "lib-router",
149
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
150
- priority: 0
151
- };
152
- }
153
- if (!Object.keys(extraGroups).length) {
154
- return;
155
- }
156
- chain.optimization.splitChunks({
157
- ...currentConfig,
158
- cacheGroups: {
159
- ...currentConfig.cacheGroups,
160
- ...extraGroups
161
- }
202
+ const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
203
+ const applySplitChunksRule = function(api) {
204
+ let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {
205
+ react: true,
206
+ router: true
207
+ };
208
+ api.modifyBundlerChain((chain, param)=>{
209
+ let { environment, isProd } = param;
210
+ const { config } = environment;
211
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
212
+ const currentConfig = chain.optimization.splitChunks.values();
213
+ if (!isPlainObject(currentConfig)) return;
214
+ const extraGroups = {};
215
+ if (options.react) extraGroups.react = {
216
+ name: 'lib-react',
217
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
218
+ priority: 0
219
+ };
220
+ if (options.router) extraGroups.router = {
221
+ name: 'lib-router',
222
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
223
+ priority: 0
224
+ };
225
+ if (!Object.keys(extraGroups).length) return;
226
+ chain.optimization.splitChunks({
227
+ ...currentConfig,
228
+ cacheGroups: {
229
+ ...currentConfig.cacheGroups,
230
+ ...extraGroups
231
+ }
232
+ });
162
233
  });
163
- });
164
234
  };
165
-
166
- // src/index.ts
167
- var PLUGIN_REACT_NAME = "rsbuild:react";
168
- var pluginReact = ({
169
- enableProfiler = false,
170
- ...options
171
- } = {}) => ({
172
- name: PLUGIN_REACT_NAME,
173
- setup(api) {
174
- if (api.context.bundlerType === "rspack") {
175
- applyBasicReactSupport(api, options);
176
- if (enableProfiler) {
177
- applyReactProfiler(api);
178
- }
179
- }
180
- applySplitChunksRule(api, options?.splitChunks);
181
- }
182
- });
183
- // Annotate the CommonJS export names for ESM import in node:
184
- 0 && (module.exports = {
185
- PLUGIN_REACT_NAME,
186
- pluginReact
235
+ const PLUGIN_REACT_NAME = 'rsbuild:react';
236
+ const pluginReact = function() {
237
+ let { enableProfiler = false, ...options } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
238
+ return {
239
+ name: PLUGIN_REACT_NAME,
240
+ setup (api) {
241
+ if ('rspack' === api.context.bundlerType) {
242
+ applyBasicReactSupport(api, options);
243
+ if (enableProfiler) applyReactProfiler(api);
244
+ }
245
+ applySplitChunksRule(api, null == options ? void 0 : options.splitChunks);
246
+ }
247
+ };
248
+ };
249
+ var __webpack_export_target__ = exports;
250
+ for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
251
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
252
+ value: true
187
253
  });
package/dist/index.js CHANGED
@@ -1,164 +1,132 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined")
8
- return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
10
- });
11
-
12
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.60.1_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
13
- import path from "path";
14
- import { fileURLToPath } from "url";
15
-
16
- // src/react.ts
17
- import path2 from "path";
18
- var applyBasicReactSupport = (api, options) => {
19
- const REACT_REFRESH_PATH = __require.resolve("react-refresh");
20
- api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig }) => {
21
- const isDev = userConfig.mode === "development";
22
- const reactOptions = {
23
- development: isDev,
24
- refresh: isDev && userConfig.dev.hmr && userConfig.output.target === "web",
25
- runtime: "automatic",
26
- ...options.swcReactOptions
27
- };
28
- const extraConfig = {
29
- tools: {
30
- swc: {
31
- jsc: {
32
- parser: {
33
- syntax: "typescript",
34
- // enable supports for JSX/TSX compilation
35
- tsx: true
36
- },
37
- transform: {
38
- react: reactOptions
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
3
+ const react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
4
+ const applyBasicReactSupport = (api, options)=>{
5
+ const REACT_REFRESH_PATH = react_require.resolve('react-refresh');
6
+ api.modifyEnvironmentConfig((userConfig, param)=>{
7
+ let { mergeEnvironmentConfig } = param;
8
+ const isDev = 'development' === userConfig.mode;
9
+ const reactOptions = {
10
+ development: isDev,
11
+ refresh: isDev && userConfig.dev.hmr && 'web' === userConfig.output.target,
12
+ runtime: 'automatic',
13
+ ...options.swcReactOptions
14
+ };
15
+ const extraConfig = {
16
+ tools: {
17
+ swc: {
18
+ jsc: {
19
+ parser: {
20
+ syntax: 'typescript',
21
+ // enable supports for JSX/TSX compilation
22
+ tsx: true
23
+ },
24
+ transform: {
25
+ react: reactOptions
26
+ }
27
+ }
28
+ }
39
29
  }
40
- }
41
- }
42
- }
43
- };
44
- return mergeEnvironmentConfig(extraConfig, userConfig);
45
- });
46
- api.modifyBundlerChain(
47
- async (chain, { CHAIN_ID, environment, isDev, target }) => {
48
- const { config } = environment;
49
- const usingHMR = isDev && config.dev.hmr && target === "web";
50
- if (!usingHMR) {
51
- return;
52
- }
53
- chain.resolve.alias.set(
54
- "react-refresh",
55
- path2.dirname(REACT_REFRESH_PATH)
56
- );
57
- const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
58
- const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
59
- const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
60
- chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
61
- {
62
- include: [SCRIPT_REGEX],
63
- exclude: [NODE_MODULES_REGEX],
64
- ...options.reactRefreshOptions
65
- }
66
- ]);
67
- }
68
- );
30
+ };
31
+ return mergeEnvironmentConfig(extraConfig, userConfig);
32
+ });
33
+ api.modifyBundlerChain(async (chain, param)=>{
34
+ let { CHAIN_ID, environment, isDev, target } = param;
35
+ const { config } = environment;
36
+ const usingHMR = isDev && config.dev.hmr && 'web' === target;
37
+ if (!usingHMR) return;
38
+ chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(REACT_REFRESH_PATH));
39
+ const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
40
+ const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
41
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
42
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
43
+ {
44
+ include: [
45
+ SCRIPT_REGEX
46
+ ],
47
+ exclude: [
48
+ NODE_MODULES_REGEX
49
+ ],
50
+ ...options.reactRefreshOptions
51
+ }
52
+ ]);
53
+ });
69
54
  };
70
- var applyReactProfiler = (api) => {
71
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig }) => {
72
- if (config.mode !== "production") {
73
- return;
74
- }
75
- const enableProfilerConfig = {
76
- output: {
77
- minify: {
78
- jsOptions: {
79
- minimizerOptions: {
80
- // Need to keep classnames and function names like Components for debugging purposes.
81
- mangle: {
82
- keep_classnames: true,
83
- keep_fnames: true
84
- }
55
+ const applyReactProfiler = (api)=>{
56
+ api.modifyEnvironmentConfig((config, param)=>{
57
+ let { mergeEnvironmentConfig } = param;
58
+ if ('production' !== config.mode) return;
59
+ const enableProfilerConfig = {
60
+ output: {
61
+ minify: {
62
+ jsOptions: {
63
+ minimizerOptions: {
64
+ // Need to keep classnames and function names like Components for debugging purposes.
65
+ mangle: {
66
+ keep_classnames: true,
67
+ keep_fnames: true
68
+ }
69
+ }
70
+ }
71
+ }
85
72
  }
86
- }
87
- }
88
- }
89
- };
90
- return mergeEnvironmentConfig(config, enableProfilerConfig);
91
- });
92
- api.modifyBundlerChain((chain, { isProd }) => {
93
- if (!isProd) {
94
- return;
95
- }
96
- chain.resolve.alias.set("react-dom$", "react-dom/profiling");
97
- chain.resolve.alias.set("scheduler/tracing", "scheduler/tracing-profiling");
98
- });
73
+ };
74
+ return mergeEnvironmentConfig(config, enableProfilerConfig);
75
+ });
76
+ api.modifyBundlerChain((chain, param)=>{
77
+ let { isProd } = param;
78
+ if (!isProd) return;
79
+ // Replace react-dom with the profiling version.
80
+ // Reference: https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977
81
+ chain.resolve.alias.set('react-dom$', 'react-dom/profiling');
82
+ chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
83
+ });
99
84
  };
100
-
101
- // src/splitChunks.ts
102
- var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
103
- var applySplitChunksRule = (api, options = {
104
- react: true,
105
- router: true
106
- }) => {
107
- api.modifyBundlerChain((chain, { environment, isProd }) => {
108
- const { config } = environment;
109
- if (config.performance.chunkSplit.strategy !== "split-by-experience") {
110
- return;
111
- }
112
- const currentConfig = chain.optimization.splitChunks.values();
113
- if (!isPlainObject(currentConfig)) {
114
- return;
115
- }
116
- const extraGroups = {};
117
- if (options.react) {
118
- extraGroups.react = {
119
- name: "lib-react",
120
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
121
- priority: 0
122
- };
123
- }
124
- if (options.router) {
125
- extraGroups.router = {
126
- name: "lib-router",
127
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
128
- priority: 0
129
- };
130
- }
131
- if (!Object.keys(extraGroups).length) {
132
- return;
133
- }
134
- chain.optimization.splitChunks({
135
- ...currentConfig,
136
- cacheGroups: {
137
- ...currentConfig.cacheGroups,
138
- ...extraGroups
139
- }
85
+ const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
86
+ const applySplitChunksRule = function(api) {
87
+ let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {
88
+ react: true,
89
+ router: true
90
+ };
91
+ api.modifyBundlerChain((chain, param)=>{
92
+ let { environment, isProd } = param;
93
+ const { config } = environment;
94
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
95
+ const currentConfig = chain.optimization.splitChunks.values();
96
+ if (!isPlainObject(currentConfig)) return;
97
+ const extraGroups = {};
98
+ if (options.react) extraGroups.react = {
99
+ name: 'lib-react',
100
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
101
+ priority: 0
102
+ };
103
+ if (options.router) extraGroups.router = {
104
+ name: 'lib-router',
105
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
106
+ priority: 0
107
+ };
108
+ if (!Object.keys(extraGroups).length) return;
109
+ chain.optimization.splitChunks({
110
+ ...currentConfig,
111
+ cacheGroups: {
112
+ ...currentConfig.cacheGroups,
113
+ ...extraGroups
114
+ }
115
+ });
140
116
  });
141
- });
142
117
  };
143
-
144
- // src/index.ts
145
- var PLUGIN_REACT_NAME = "rsbuild:react";
146
- var pluginReact = ({
147
- enableProfiler = false,
148
- ...options
149
- } = {}) => ({
150
- name: PLUGIN_REACT_NAME,
151
- setup(api) {
152
- if (api.context.bundlerType === "rspack") {
153
- applyBasicReactSupport(api, options);
154
- if (enableProfiler) {
155
- applyReactProfiler(api);
156
- }
157
- }
158
- applySplitChunksRule(api, options?.splitChunks);
159
- }
160
- });
161
- export {
162
- PLUGIN_REACT_NAME,
163
- pluginReact
118
+ const PLUGIN_REACT_NAME = 'rsbuild:react';
119
+ const pluginReact = function() {
120
+ let { enableProfiler = false, ...options } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
121
+ return {
122
+ name: PLUGIN_REACT_NAME,
123
+ setup (api) {
124
+ if ('rspack' === api.context.bundlerType) {
125
+ applyBasicReactSupport(api, options);
126
+ if (enableProfiler) applyReactProfiler(api);
127
+ }
128
+ applySplitChunksRule(api, null == options ? void 0 : options.splitChunks);
129
+ }
130
+ };
164
131
  };
132
+ export { PLUGIN_REACT_NAME, pluginReact };
@@ -1,4 +1,4 @@
1
1
  import type { RsbuildPluginAPI } from '@rsbuild/core';
2
- import type { PluginReactOptions } from '.';
2
+ import type { PluginReactOptions } from './index.js';
3
3
  export declare const applyBasicReactSupport: (api: RsbuildPluginAPI, options: PluginReactOptions) => void;
4
4
  export declare const applyReactProfiler: (api: RsbuildPluginAPI) => void;
@@ -1,3 +1,3 @@
1
1
  import type { RsbuildPluginAPI } from '@rsbuild/core';
2
- import type { SplitReactChunkOptions } from '.';
2
+ import type { SplitReactChunkOptions } from './index.js';
3
3
  export declare const applySplitChunksRule: (api: RsbuildPluginAPI, options?: SplitReactChunkOptions) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,25 +11,24 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./dist-types/index.d.ts",
14
+ "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js",
16
16
  "require": "./dist/index.cjs"
17
17
  }
18
18
  },
19
19
  "main": "./dist/index.cjs",
20
- "types": "./dist-types/index.d.ts",
20
+ "types": "./dist/index.d.ts",
21
21
  "files": [
22
- "dist",
23
- "dist-types"
22
+ "dist"
24
23
  ],
25
24
  "dependencies": {
26
- "@rspack/plugin-react-refresh": "1.0.0",
25
+ "@rspack/plugin-react-refresh": "~1.0.0",
27
26
  "react-refresh": "^0.14.2"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@types/node": "18.x",
31
- "typescript": "^5.5.2",
32
- "@rsbuild/core": "1.0.8",
30
+ "typescript": "^5.6.3",
31
+ "@rsbuild/core": "1.0.14",
33
32
  "@scripts/test-helper": "1.0.1"
34
33
  },
35
34
  "peerDependencies": {
@@ -41,7 +40,7 @@
41
40
  "registry": "https://registry.npmjs.org/"
42
41
  },
43
42
  "scripts": {
44
- "build": "modern build",
45
- "dev": "modern build --watch"
43
+ "build": "rslib build",
44
+ "dev": "rslib build --watch"
46
45
  }
47
46
  }
@@ -1 +0,0 @@
1
- {"//":"This file is for making TypeScript work with moduleResolution node16+.","version":"1.0.0"}
File without changes