@rsbuild/plugin-react 0.6.4 → 0.6.5
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.d.ts +2 -1
- package/dist/index.js +31 -1
- package/dist/index.mjs +31 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,9 @@ type PluginReactOptions = {
|
|
|
25
25
|
* Configuration for chunk splitting of React-related dependencies.
|
|
26
26
|
*/
|
|
27
27
|
splitChunks?: SplitReactChunkOptions;
|
|
28
|
+
enableProfiler?: boolean;
|
|
28
29
|
};
|
|
29
30
|
declare const PLUGIN_REACT_NAME = "rsbuild:react";
|
|
30
|
-
declare const pluginReact: (options?: PluginReactOptions) => RsbuildPlugin;
|
|
31
|
+
declare const pluginReact: ({ enableProfiler, ...options }?: PluginReactOptions) => RsbuildPlugin;
|
|
31
32
|
|
|
32
33
|
export { PLUGIN_REACT_NAME, type PluginReactOptions, type SplitReactChunkOptions, pluginReact };
|
package/dist/index.js
CHANGED
|
@@ -116,14 +116,44 @@ var applyBasicReactSupport = (api, options) => {
|
|
|
116
116
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [{ include: [import_shared2.SCRIPT_REGEX] }]);
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
+
var applyReactProfiler = (api) => {
|
|
120
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
121
|
+
const enableProfilerConfig = {
|
|
122
|
+
output: {
|
|
123
|
+
minify: {
|
|
124
|
+
jsOptions: {
|
|
125
|
+
// Need to keep classnames and function names like Components for debugging purposes.
|
|
126
|
+
mangle: {
|
|
127
|
+
keep_classnames: true,
|
|
128
|
+
keep_fnames: true
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return mergeRsbuildConfig(config, enableProfilerConfig);
|
|
135
|
+
});
|
|
136
|
+
api.modifyBundlerChain((chain) => {
|
|
137
|
+
chain.resolve.alias.set("react-dom$", "react-dom/profiling");
|
|
138
|
+
chain.resolve.alias.set("scheduler/tracing", "scheduler/tracing-profiling");
|
|
139
|
+
});
|
|
140
|
+
};
|
|
119
141
|
|
|
120
142
|
// src/index.ts
|
|
143
|
+
var import_shared3 = require("@rsbuild/shared");
|
|
121
144
|
var PLUGIN_REACT_NAME = "rsbuild:react";
|
|
122
|
-
var pluginReact = (
|
|
145
|
+
var pluginReact = ({
|
|
146
|
+
enableProfiler = false,
|
|
147
|
+
...options
|
|
148
|
+
} = {}) => ({
|
|
123
149
|
name: PLUGIN_REACT_NAME,
|
|
124
150
|
setup(api) {
|
|
151
|
+
const isEnvProductionProfile = enableProfiler && (0, import_shared3.getNodeEnv)() === "production";
|
|
125
152
|
if (api.context.bundlerType === "rspack") {
|
|
126
153
|
applyBasicReactSupport(api, options);
|
|
154
|
+
if (isEnvProductionProfile) {
|
|
155
|
+
applyReactProfiler(api);
|
|
156
|
+
}
|
|
127
157
|
}
|
|
128
158
|
applySplitChunksRule(api, options?.splitChunks);
|
|
129
159
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -102,14 +102,44 @@ var applyBasicReactSupport = (api, options) => {
|
|
|
102
102
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [{ include: [SCRIPT_REGEX] }]);
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
|
+
var applyReactProfiler = (api) => {
|
|
106
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
107
|
+
const enableProfilerConfig = {
|
|
108
|
+
output: {
|
|
109
|
+
minify: {
|
|
110
|
+
jsOptions: {
|
|
111
|
+
// Need to keep classnames and function names like Components for debugging purposes.
|
|
112
|
+
mangle: {
|
|
113
|
+
keep_classnames: true,
|
|
114
|
+
keep_fnames: true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
return mergeRsbuildConfig(config, enableProfilerConfig);
|
|
121
|
+
});
|
|
122
|
+
api.modifyBundlerChain((chain) => {
|
|
123
|
+
chain.resolve.alias.set("react-dom$", "react-dom/profiling");
|
|
124
|
+
chain.resolve.alias.set("scheduler/tracing", "scheduler/tracing-profiling");
|
|
125
|
+
});
|
|
126
|
+
};
|
|
105
127
|
|
|
106
128
|
// src/index.ts
|
|
129
|
+
import { getNodeEnv } from "@rsbuild/shared";
|
|
107
130
|
var PLUGIN_REACT_NAME = "rsbuild:react";
|
|
108
|
-
var pluginReact = (
|
|
131
|
+
var pluginReact = ({
|
|
132
|
+
enableProfiler = false,
|
|
133
|
+
...options
|
|
134
|
+
} = {}) => ({
|
|
109
135
|
name: PLUGIN_REACT_NAME,
|
|
110
136
|
setup(api) {
|
|
137
|
+
const isEnvProductionProfile = enableProfiler && getNodeEnv() === "production";
|
|
111
138
|
if (api.context.bundlerType === "rspack") {
|
|
112
139
|
applyBasicReactSupport(api, options);
|
|
140
|
+
if (isEnvProductionProfile) {
|
|
141
|
+
applyReactProfiler(api);
|
|
142
|
+
}
|
|
113
143
|
}
|
|
114
144
|
applySplitChunksRule(api, options?.splitChunks);
|
|
115
145
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@rspack/plugin-react-refresh": "0.6.2",
|
|
26
26
|
"react-refresh": "^0.14.0",
|
|
27
|
-
"@rsbuild/shared": "0.6.
|
|
27
|
+
"@rsbuild/shared": "0.6.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "16.x",
|
|
31
31
|
"typescript": "^5.4.2",
|
|
32
|
-
"@rsbuild/core": "0.6.
|
|
33
|
-
"@scripts/test-helper": "0.6.
|
|
32
|
+
"@rsbuild/core": "0.6.5",
|
|
33
|
+
"@scripts/test-helper": "0.6.5"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@rsbuild/core": "^0.6.
|
|
36
|
+
"@rsbuild/core": "^0.6.5"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public",
|