@rsbuild/plugin-react 0.0.0-next-20231220091832 → 0.0.0-next-20240109045121
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 +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.js +17 -46
- package/dist/index.mjs +19 -50
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import { SwcReactConfig } from '@rsbuild/shared';
|
|
2
3
|
|
|
3
4
|
declare const isBeyondReact17: (cwd: string) => Promise<any>;
|
|
4
5
|
|
|
5
6
|
type SplitReactChunkOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Whether to enable split chunking for React-related dependencies (e.g., react, react-dom, scheduler).
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
6
12
|
react?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to enable split chunking for routing-related dependencies (e.g., react-router, react-router-dom, history).
|
|
15
|
+
*
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
7
18
|
router?: boolean;
|
|
8
19
|
};
|
|
9
20
|
type PluginReactOptions = {
|
|
21
|
+
/**
|
|
22
|
+
* Configure the behavior of SWC to transform React code,
|
|
23
|
+
* the same as SWC's [jsc.transform.react](https://swc.rs/docs/configuration/compilation#jsctransformreact).
|
|
24
|
+
*/
|
|
25
|
+
swcReactOptions?: SwcReactConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for chunk splitting of React-related dependencies.
|
|
28
|
+
*/
|
|
10
29
|
splitChunks?: SplitReactChunkOptions;
|
|
11
30
|
};
|
|
12
31
|
declare const pluginReact: (options?: PluginReactOptions) => RsbuildPlugin;
|
package/dist/index.js
CHANGED
|
@@ -148,68 +148,39 @@ var applySplitChunksRule = (api, options = {
|
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
// src/react.ts
|
|
151
|
+
var import_node_path = __toESM(require("path"));
|
|
151
152
|
var import_shared4 = require("@rsbuild/shared");
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const reactRefreshEntryPath = require.resolve("@rspack/plugin-react-refresh/react-refresh-entry");
|
|
157
|
-
return reactRefreshEntryPath;
|
|
158
|
-
}
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
var setupCompiler = (compiler) => {
|
|
162
|
-
if (!(0, import_shared4.isClientCompiler)(compiler)) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
166
|
-
if (!reactRefreshEntry) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
for (const key in compiler.options.entry) {
|
|
170
|
-
compiler.options.entry[key].import = [
|
|
171
|
-
reactRefreshEntry,
|
|
172
|
-
...compiler.options.entry[key].import || []
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
var applyBasicReactSupport = (api) => {
|
|
177
|
-
api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
|
|
178
|
-
if ((0, import_shared4.isProd)()) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (multiCompiler.compilers) {
|
|
182
|
-
multiCompiler.compilers.forEach(setupCompiler);
|
|
183
|
-
} else {
|
|
184
|
-
setupCompiler(multiCompiler);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd3, target }) => {
|
|
153
|
+
var REACT_REFRESH_PATH = require.resolve("react-refresh");
|
|
154
|
+
var REACT_REFRESH_DIR_PATH = import_node_path.default.dirname(REACT_REFRESH_PATH);
|
|
155
|
+
var applyBasicReactSupport = (api, options) => {
|
|
156
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
|
|
188
157
|
const config = api.getNormalizedConfig();
|
|
189
|
-
const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd:
|
|
158
|
+
const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd: isProd2, target });
|
|
190
159
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
191
160
|
const reactOptions = {
|
|
192
|
-
development: !
|
|
161
|
+
development: !isProd2,
|
|
193
162
|
refresh: usingHMR,
|
|
194
|
-
runtime: "automatic"
|
|
163
|
+
runtime: "automatic",
|
|
164
|
+
...options.swcReactOptions
|
|
195
165
|
};
|
|
196
|
-
rule.use(CHAIN_ID.USE.SWC).tap((
|
|
197
|
-
|
|
166
|
+
rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
|
|
167
|
+
options2.jsc.transform.react = {
|
|
198
168
|
...reactOptions
|
|
199
169
|
};
|
|
200
|
-
return
|
|
170
|
+
return options2;
|
|
201
171
|
});
|
|
202
172
|
if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
203
|
-
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((
|
|
204
|
-
|
|
173
|
+
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options2) => {
|
|
174
|
+
options2.jsc.transform.react = {
|
|
205
175
|
...reactOptions
|
|
206
176
|
};
|
|
207
|
-
return
|
|
177
|
+
return options2;
|
|
208
178
|
});
|
|
209
179
|
}
|
|
210
180
|
if (!usingHMR) {
|
|
211
181
|
return;
|
|
212
182
|
}
|
|
183
|
+
chain.resolve.alias.set("react-refresh", REACT_REFRESH_DIR_PATH);
|
|
213
184
|
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
214
185
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
215
186
|
});
|
|
@@ -241,7 +212,7 @@ var pluginReact = (options = {}) => ({
|
|
|
241
212
|
pre: ["rsbuild:swc"],
|
|
242
213
|
setup(api) {
|
|
243
214
|
if (api.context.bundlerType === "rspack") {
|
|
244
|
-
applyBasicReactSupport(api);
|
|
215
|
+
applyBasicReactSupport(api, options);
|
|
245
216
|
}
|
|
246
217
|
applyAntdSupport(api);
|
|
247
218
|
applyArcoSupport(api);
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
9
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.45.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
10
10
|
import { fileURLToPath } from "url";
|
|
11
11
|
import path from "path";
|
|
12
12
|
|
|
@@ -134,70 +134,39 @@ var applySplitChunksRule = (api, options = {
|
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
// src/react.ts
|
|
137
|
-
import
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
"@rspack/plugin-react-refresh/react-refresh-entry"
|
|
144
|
-
);
|
|
145
|
-
return reactRefreshEntryPath;
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
var setupCompiler = (compiler) => {
|
|
150
|
-
if (!isClientCompiler(compiler)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
154
|
-
if (!reactRefreshEntry) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
for (const key in compiler.options.entry) {
|
|
158
|
-
compiler.options.entry[key].import = [
|
|
159
|
-
reactRefreshEntry,
|
|
160
|
-
...compiler.options.entry[key].import || []
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var applyBasicReactSupport = (api) => {
|
|
165
|
-
api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
|
|
166
|
-
if (isProd2()) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (multiCompiler.compilers) {
|
|
170
|
-
multiCompiler.compilers.forEach(setupCompiler);
|
|
171
|
-
} else {
|
|
172
|
-
setupCompiler(multiCompiler);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd3, target }) => {
|
|
137
|
+
import path2 from "path";
|
|
138
|
+
import { isUsingHMR } from "@rsbuild/shared";
|
|
139
|
+
var REACT_REFRESH_PATH = __require.resolve("react-refresh");
|
|
140
|
+
var REACT_REFRESH_DIR_PATH = path2.dirname(REACT_REFRESH_PATH);
|
|
141
|
+
var applyBasicReactSupport = (api, options) => {
|
|
142
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
|
|
176
143
|
const config = api.getNormalizedConfig();
|
|
177
|
-
const usingHMR = isUsingHMR(config, { isProd:
|
|
144
|
+
const usingHMR = isUsingHMR(config, { isProd: isProd2, target });
|
|
178
145
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
179
146
|
const reactOptions = {
|
|
180
|
-
development: !
|
|
147
|
+
development: !isProd2,
|
|
181
148
|
refresh: usingHMR,
|
|
182
|
-
runtime: "automatic"
|
|
149
|
+
runtime: "automatic",
|
|
150
|
+
...options.swcReactOptions
|
|
183
151
|
};
|
|
184
|
-
rule.use(CHAIN_ID.USE.SWC).tap((
|
|
185
|
-
|
|
152
|
+
rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
|
|
153
|
+
options2.jsc.transform.react = {
|
|
186
154
|
...reactOptions
|
|
187
155
|
};
|
|
188
|
-
return
|
|
156
|
+
return options2;
|
|
189
157
|
});
|
|
190
158
|
if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
191
|
-
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((
|
|
192
|
-
|
|
159
|
+
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options2) => {
|
|
160
|
+
options2.jsc.transform.react = {
|
|
193
161
|
...reactOptions
|
|
194
162
|
};
|
|
195
|
-
return
|
|
163
|
+
return options2;
|
|
196
164
|
});
|
|
197
165
|
}
|
|
198
166
|
if (!usingHMR) {
|
|
199
167
|
return;
|
|
200
168
|
}
|
|
169
|
+
chain.resolve.alias.set("react-refresh", REACT_REFRESH_DIR_PATH);
|
|
201
170
|
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
202
171
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
203
172
|
});
|
|
@@ -229,7 +198,7 @@ var pluginReact = (options = {}) => ({
|
|
|
229
198
|
pre: ["rsbuild:swc"],
|
|
230
199
|
setup(api) {
|
|
231
200
|
if (api.context.bundlerType === "rspack") {
|
|
232
|
-
applyBasicReactSupport(api);
|
|
201
|
+
applyBasicReactSupport(api, options);
|
|
233
202
|
}
|
|
234
203
|
applyAntdSupport(api);
|
|
235
204
|
applyArcoSupport(api);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240109045121",
|
|
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": "0.4.
|
|
25
|
+
"@rspack/plugin-react-refresh": "0.4.5-canary-be59383-20240105051840",
|
|
26
26
|
"react-refresh": "^0.14.0",
|
|
27
|
-
"@rsbuild/shared": "0.0.0-next-
|
|
27
|
+
"@rsbuild/shared": "0.0.0-next-20240109045121"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "16.x",
|
|
31
31
|
"typescript": "^5.3.0",
|
|
32
|
-
"@rsbuild/core": "0.0.0-next-
|
|
33
|
-
"@rsbuild/test-helper": "0.0.0-next-
|
|
32
|
+
"@rsbuild/core": "0.0.0-next-20240109045121",
|
|
33
|
+
"@rsbuild/test-helper": "0.0.0-next-20240109045121"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public",
|