@rsbuild/plugin-react 0.6.5 → 0.6.6
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 -3
- package/dist/index.js +51 -51
- package/dist/index.mjs +53 -51
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { SwcReactConfig } from '@rsbuild/shared';
|
|
1
|
+
import { Rspack, RsbuildPlugin } from '@rsbuild/core';
|
|
3
2
|
|
|
4
3
|
type SplitReactChunkOptions = {
|
|
5
4
|
/**
|
|
@@ -20,7 +19,7 @@ type PluginReactOptions = {
|
|
|
20
19
|
* Configure the behavior of SWC to transform React code,
|
|
21
20
|
* the same as SWC's [jsc.transform.react](https://swc.rs/docs/configuration/compilation#jsctransformreact).
|
|
22
21
|
*/
|
|
23
|
-
swcReactOptions?:
|
|
22
|
+
swcReactOptions?: Rspack.SwcLoaderTransformConfig['react'];
|
|
24
23
|
/**
|
|
25
24
|
* Configuration for chunk splitting of React-related dependencies.
|
|
26
25
|
*/
|
package/dist/index.js
CHANGED
|
@@ -34,68 +34,23 @@ __export(src_exports, {
|
|
|
34
34
|
pluginReact: () => pluginReact
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
|
|
38
|
-
// src/splitChunks.ts
|
|
39
|
-
var import_shared = require("@rsbuild/shared");
|
|
40
|
-
var applySplitChunksRule = (api, options = {
|
|
41
|
-
react: true,
|
|
42
|
-
router: true
|
|
43
|
-
}) => {
|
|
44
|
-
api.modifyBundlerChain((chain) => {
|
|
45
|
-
const config = api.getNormalizedConfig();
|
|
46
|
-
if (config.performance.chunkSplit.strategy !== "split-by-experience") {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const currentConfig = chain.optimization.splitChunks.values();
|
|
50
|
-
if (!(0, import_shared.isPlainObject)(currentConfig)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const extraGroups = {};
|
|
54
|
-
if (options.react) {
|
|
55
|
-
extraGroups.react = [
|
|
56
|
-
"react",
|
|
57
|
-
"react-dom",
|
|
58
|
-
"scheduler",
|
|
59
|
-
...(0, import_shared.isProd)() ? [] : ["react-refresh", /@rspack[\\/]plugin-react-refresh/]
|
|
60
|
-
];
|
|
61
|
-
}
|
|
62
|
-
if (options.router) {
|
|
63
|
-
extraGroups.router = [
|
|
64
|
-
"react-router",
|
|
65
|
-
"react-router-dom",
|
|
66
|
-
"history",
|
|
67
|
-
/@remix-run[\\/]router/
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
if (!Object.keys(extraGroups).length) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
chain.optimization.splitChunks({
|
|
74
|
-
...currentConfig,
|
|
75
|
-
// @ts-expect-error Rspack and Webpack uses different cacheGroups type
|
|
76
|
-
cacheGroups: {
|
|
77
|
-
...currentConfig.cacheGroups,
|
|
78
|
-
...(0, import_shared.createCacheGroups)(extraGroups)
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
37
|
+
var import_shared3 = require("@rsbuild/shared");
|
|
83
38
|
|
|
84
39
|
// src/react.ts
|
|
85
40
|
var import_node_path = __toESM(require("path"));
|
|
86
|
-
var
|
|
41
|
+
var import_shared = require("@rsbuild/shared");
|
|
87
42
|
var applyBasicReactSupport = (api, options) => {
|
|
88
43
|
const REACT_REFRESH_PATH = require.resolve("react-refresh");
|
|
89
44
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, isDev, isProd: isProd2, target }) => {
|
|
90
45
|
const config = api.getNormalizedConfig();
|
|
91
|
-
const usingHMR = (0,
|
|
46
|
+
const usingHMR = (0, import_shared.isUsingHMR)(config, { isProd: isProd2, target });
|
|
92
47
|
const reactOptions = {
|
|
93
48
|
development: isDev,
|
|
94
49
|
refresh: usingHMR,
|
|
95
50
|
runtime: "automatic",
|
|
96
51
|
...options.swcReactOptions
|
|
97
52
|
};
|
|
98
|
-
(0,
|
|
53
|
+
(0, import_shared.modifySwcLoaderOptions)({
|
|
99
54
|
chain,
|
|
100
55
|
modifier: (opts) => {
|
|
101
56
|
var _a;
|
|
@@ -113,7 +68,7 @@ var applyBasicReactSupport = (api, options) => {
|
|
|
113
68
|
}
|
|
114
69
|
chain.resolve.alias.set("react-refresh", import_node_path.default.dirname(REACT_REFRESH_PATH));
|
|
115
70
|
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
116
|
-
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [{ include: [
|
|
71
|
+
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [{ include: [import_shared.SCRIPT_REGEX] }]);
|
|
117
72
|
});
|
|
118
73
|
};
|
|
119
74
|
var applyReactProfiler = (api) => {
|
|
@@ -139,8 +94,53 @@ var applyReactProfiler = (api) => {
|
|
|
139
94
|
});
|
|
140
95
|
};
|
|
141
96
|
|
|
97
|
+
// src/splitChunks.ts
|
|
98
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
99
|
+
var applySplitChunksRule = (api, options = {
|
|
100
|
+
react: true,
|
|
101
|
+
router: true
|
|
102
|
+
}) => {
|
|
103
|
+
api.modifyBundlerChain((chain) => {
|
|
104
|
+
const config = api.getNormalizedConfig();
|
|
105
|
+
if (config.performance.chunkSplit.strategy !== "split-by-experience") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const currentConfig = chain.optimization.splitChunks.values();
|
|
109
|
+
if (!(0, import_shared2.isPlainObject)(currentConfig)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const extraGroups = {};
|
|
113
|
+
if (options.react) {
|
|
114
|
+
extraGroups.react = [
|
|
115
|
+
"react",
|
|
116
|
+
"react-dom",
|
|
117
|
+
"scheduler",
|
|
118
|
+
...(0, import_shared2.isProd)() ? [] : ["react-refresh", /@rspack[\\/]plugin-react-refresh/]
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
if (options.router) {
|
|
122
|
+
extraGroups.router = [
|
|
123
|
+
"react-router",
|
|
124
|
+
"react-router-dom",
|
|
125
|
+
"history",
|
|
126
|
+
/@remix-run[\\/]router/
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
if (!Object.keys(extraGroups).length) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
chain.optimization.splitChunks({
|
|
133
|
+
...currentConfig,
|
|
134
|
+
// @ts-expect-error Rspack and Webpack uses different cacheGroups type
|
|
135
|
+
cacheGroups: {
|
|
136
|
+
...currentConfig.cacheGroups,
|
|
137
|
+
...(0, import_shared2.createCacheGroups)(extraGroups)
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
142
143
|
// src/index.ts
|
|
143
|
-
var import_shared3 = require("@rsbuild/shared");
|
|
144
144
|
var PLUGIN_REACT_NAME = "rsbuild:react";
|
|
145
145
|
var pluginReact = ({
|
|
146
146
|
enableProfiler = false,
|
package/dist/index.mjs
CHANGED
|
@@ -13,61 +13,14 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
import path from "path";
|
|
15
15
|
|
|
16
|
-
// src/
|
|
17
|
-
import {
|
|
18
|
-
isProd,
|
|
19
|
-
isPlainObject,
|
|
20
|
-
createCacheGroups
|
|
21
|
-
} from "@rsbuild/shared";
|
|
22
|
-
var applySplitChunksRule = (api, options = {
|
|
23
|
-
react: true,
|
|
24
|
-
router: true
|
|
25
|
-
}) => {
|
|
26
|
-
api.modifyBundlerChain((chain) => {
|
|
27
|
-
const config = api.getNormalizedConfig();
|
|
28
|
-
if (config.performance.chunkSplit.strategy !== "split-by-experience") {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const currentConfig = chain.optimization.splitChunks.values();
|
|
32
|
-
if (!isPlainObject(currentConfig)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const extraGroups = {};
|
|
36
|
-
if (options.react) {
|
|
37
|
-
extraGroups.react = [
|
|
38
|
-
"react",
|
|
39
|
-
"react-dom",
|
|
40
|
-
"scheduler",
|
|
41
|
-
...isProd() ? [] : ["react-refresh", /@rspack[\\/]plugin-react-refresh/]
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
if (options.router) {
|
|
45
|
-
extraGroups.router = [
|
|
46
|
-
"react-router",
|
|
47
|
-
"react-router-dom",
|
|
48
|
-
"history",
|
|
49
|
-
/@remix-run[\\/]router/
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
if (!Object.keys(extraGroups).length) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
chain.optimization.splitChunks({
|
|
56
|
-
...currentConfig,
|
|
57
|
-
// @ts-expect-error Rspack and Webpack uses different cacheGroups type
|
|
58
|
-
cacheGroups: {
|
|
59
|
-
...currentConfig.cacheGroups,
|
|
60
|
-
...createCacheGroups(extraGroups)
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
};
|
|
16
|
+
// src/index.ts
|
|
17
|
+
import { getNodeEnv } from "@rsbuild/shared";
|
|
65
18
|
|
|
66
19
|
// src/react.ts
|
|
67
20
|
import path2 from "path";
|
|
68
21
|
import {
|
|
69
|
-
isUsingHMR,
|
|
70
22
|
SCRIPT_REGEX,
|
|
23
|
+
isUsingHMR,
|
|
71
24
|
modifySwcLoaderOptions
|
|
72
25
|
} from "@rsbuild/shared";
|
|
73
26
|
var applyBasicReactSupport = (api, options) => {
|
|
@@ -125,8 +78,57 @@ var applyReactProfiler = (api) => {
|
|
|
125
78
|
});
|
|
126
79
|
};
|
|
127
80
|
|
|
81
|
+
// src/splitChunks.ts
|
|
82
|
+
import {
|
|
83
|
+
createCacheGroups,
|
|
84
|
+
isPlainObject,
|
|
85
|
+
isProd
|
|
86
|
+
} from "@rsbuild/shared";
|
|
87
|
+
var applySplitChunksRule = (api, options = {
|
|
88
|
+
react: true,
|
|
89
|
+
router: true
|
|
90
|
+
}) => {
|
|
91
|
+
api.modifyBundlerChain((chain) => {
|
|
92
|
+
const config = api.getNormalizedConfig();
|
|
93
|
+
if (config.performance.chunkSplit.strategy !== "split-by-experience") {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const currentConfig = chain.optimization.splitChunks.values();
|
|
97
|
+
if (!isPlainObject(currentConfig)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const extraGroups = {};
|
|
101
|
+
if (options.react) {
|
|
102
|
+
extraGroups.react = [
|
|
103
|
+
"react",
|
|
104
|
+
"react-dom",
|
|
105
|
+
"scheduler",
|
|
106
|
+
...isProd() ? [] : ["react-refresh", /@rspack[\\/]plugin-react-refresh/]
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
if (options.router) {
|
|
110
|
+
extraGroups.router = [
|
|
111
|
+
"react-router",
|
|
112
|
+
"react-router-dom",
|
|
113
|
+
"history",
|
|
114
|
+
/@remix-run[\\/]router/
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
if (!Object.keys(extraGroups).length) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
chain.optimization.splitChunks({
|
|
121
|
+
...currentConfig,
|
|
122
|
+
// @ts-expect-error Rspack and Webpack uses different cacheGroups type
|
|
123
|
+
cacheGroups: {
|
|
124
|
+
...currentConfig.cacheGroups,
|
|
125
|
+
...createCacheGroups(extraGroups)
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
128
131
|
// src/index.ts
|
|
129
|
-
import { getNodeEnv } from "@rsbuild/shared";
|
|
130
132
|
var PLUGIN_REACT_NAME = "rsbuild:react";
|
|
131
133
|
var pluginReact = ({
|
|
132
134
|
enableProfiler = false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rspack/plugin-react-refresh": "0.6.
|
|
25
|
+
"@rspack/plugin-react-refresh": "0.6.3",
|
|
26
26
|
"react-refresh": "^0.14.0",
|
|
27
|
-
"@rsbuild/shared": "0.6.
|
|
27
|
+
"@rsbuild/shared": "0.6.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "
|
|
30
|
+
"@types/node": "18.x",
|
|
31
31
|
"typescript": "^5.4.2",
|
|
32
|
-
"@rsbuild/core": "0.6.
|
|
33
|
-
"@scripts/test-helper": "0.6.
|
|
32
|
+
"@rsbuild/core": "0.6.6",
|
|
33
|
+
"@scripts/test-helper": "0.6.6"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@rsbuild/core": "^0.6.
|
|
36
|
+
"@rsbuild/core": "^0.6.6"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public",
|