@rsbuild/plugin-react 2.0.1 → 2.1.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/dist/index.d.ts +8 -1
- package/dist/index.js +18 -11
- package/package.json +20 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RsbuildPlugin, type Rspack } from '@rsbuild/core';
|
|
2
2
|
import type { PluginOptions as ReactRefreshOptions } from '@rspack/plugin-react-refresh';
|
|
3
3
|
export type SplitReactChunkOptions = {
|
|
4
4
|
/**
|
|
@@ -12,12 +12,19 @@ export type SplitReactChunkOptions = {
|
|
|
12
12
|
* @default true
|
|
13
13
|
*/ router?: boolean;
|
|
14
14
|
};
|
|
15
|
+
export type ReactCompilerOptions = Exclude<NonNullable<Rspack.SwcLoaderTransformConfig['reactCompiler']>, boolean>;
|
|
15
16
|
export type PluginReactOptions = {
|
|
16
17
|
/**
|
|
17
18
|
* Configure the behavior of SWC to transform React code,
|
|
18
19
|
* the same as SWC's [jsc.transform.react](https://swc.rs/docs/configuration/compilation#jsctransformreact).
|
|
19
20
|
*/ swcReactOptions?: Rspack.SwcLoaderTransformConfig['react'];
|
|
20
21
|
/**
|
|
22
|
+
* Enable or configure React Compiler via `builtin:swc-loader`,
|
|
23
|
+
* the same as Rspack's `jsc.transform.reactCompiler` option.
|
|
24
|
+
*
|
|
25
|
+
* @see https://rspack.rs/guide/tech/react#using-builtinswc-loader
|
|
26
|
+
*/ reactCompiler?: Rspack.SwcLoaderTransformConfig['reactCompiler'];
|
|
27
|
+
/**
|
|
21
28
|
* Configuration for chunk splitting of React-related dependencies when `chunkSplit.strategy`
|
|
22
29
|
* is set to `split-by-experience`.
|
|
23
30
|
* @default true
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import node_path from "node:path";
|
|
3
|
+
import { rspack } from "@rsbuild/core";
|
|
3
4
|
function applySplitChunksRule(api, options) {
|
|
4
5
|
api.modifyBundlerChain((chain, { environment, isProd })=>{
|
|
5
6
|
let { config } = environment;
|
|
@@ -34,6 +35,10 @@ let src_require = createRequire(import.meta.url), PLUGIN_REACT_NAME = 'rsbuild:r
|
|
|
34
35
|
function assertCoreVersion(version) {
|
|
35
36
|
if ('1' === version.split('.')[0]) throw Error('"@rsbuild/plugin-react" v2 requires "@rsbuild/core" >= 2.0. Please upgrade "@rsbuild/core" or use "@rsbuild/plugin-react" v1.');
|
|
36
37
|
}
|
|
38
|
+
function assertReactCompilerVersion() {
|
|
39
|
+
let [majorVersion, minorVersion] = rspack.rspackVersion.split('.'), major = Number(majorVersion), minor = Number(minorVersion);
|
|
40
|
+
if (major < 2 || 2 === major && minor < 1) throw Error(`"@rsbuild/plugin-react" requires "@rspack/core" >= 2.1.0 to use the "reactCompiler" option, but found ${rspack.rspackVersion}.`);
|
|
41
|
+
}
|
|
37
42
|
function applyReactProfiler(api) {
|
|
38
43
|
let hasReactDomClientCache;
|
|
39
44
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
@@ -76,21 +81,23 @@ let pluginReact = (options = {})=>({
|
|
|
76
81
|
splitChunks: !0,
|
|
77
82
|
enableProfiler: !1,
|
|
78
83
|
...options
|
|
79
|
-
}
|
|
84
|
+
};
|
|
85
|
+
void 0 !== finalOptions.reactCompiler && assertReactCompilerVersion();
|
|
86
|
+
let reactRefreshPath = finalOptions.fastRefresh ? src_require.resolve('react-refresh') : '';
|
|
80
87
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
81
|
-
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target
|
|
82
|
-
|
|
88
|
+
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target, transformOptions = {
|
|
89
|
+
react: {
|
|
90
|
+
development: isDev,
|
|
91
|
+
refresh: usingHMR && finalOptions.fastRefresh,
|
|
92
|
+
runtime: 'automatic',
|
|
93
|
+
...finalOptions.swcReactOptions
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return void 0 !== finalOptions.reactCompiler && (transformOptions.reactCompiler = finalOptions.reactCompiler), mergeEnvironmentConfig({
|
|
83
97
|
tools: {
|
|
84
98
|
swc: {
|
|
85
99
|
jsc: {
|
|
86
|
-
transform:
|
|
87
|
-
react: {
|
|
88
|
-
development: isDev,
|
|
89
|
-
refresh: usingHMR && finalOptions.fastRefresh,
|
|
90
|
-
runtime: 'automatic',
|
|
91
|
-
...finalOptions.swcReactOptions
|
|
92
|
-
}
|
|
93
|
-
}
|
|
100
|
+
transform: transformOptions
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
}
|
package/package.json
CHANGED
|
@@ -1,48 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
|
+
"homepage": "https://rsbuild.rs",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/web-infra-dev/rsbuild/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
5
10
|
"repository": {
|
|
6
11
|
"type": "git",
|
|
7
12
|
"url": "https://github.com/web-infra-dev/rsbuild",
|
|
8
13
|
"directory": "packages/plugin-react"
|
|
9
14
|
},
|
|
10
|
-
"
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
11
18
|
"type": "module",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
12
20
|
"exports": {
|
|
13
21
|
".": {
|
|
14
22
|
"types": "./dist/index.d.ts",
|
|
15
23
|
"default": "./dist/index.js"
|
|
16
24
|
}
|
|
17
25
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"registry": "https://registry.npmjs.org/"
|
|
29
|
+
},
|
|
22
30
|
"dependencies": {
|
|
23
|
-
"@rspack/plugin-react-refresh": "2.0.
|
|
31
|
+
"@rspack/plugin-react-refresh": "^2.0.2",
|
|
24
32
|
"react-refresh": "^0.18.0"
|
|
25
33
|
},
|
|
26
34
|
"devDependencies": {
|
|
27
35
|
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.5",
|
|
28
|
-
"@rslib/core": "0.
|
|
29
|
-
"@types/node": "^24.
|
|
36
|
+
"@rslib/core": "0.23.0",
|
|
37
|
+
"@types/node": "^24.13.2",
|
|
30
38
|
"typescript": "^6.0.3",
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
39
|
+
"@scripts/test-helper": "1.0.0",
|
|
40
|
+
"@rsbuild/core": "2.0.15"
|
|
33
41
|
},
|
|
34
42
|
"peerDependencies": {
|
|
35
|
-
"@rsbuild/core": "^2.0.0
|
|
43
|
+
"@rsbuild/core": "^2.0.0"
|
|
36
44
|
},
|
|
37
45
|
"peerDependenciesMeta": {
|
|
38
46
|
"@rsbuild/core": {
|
|
39
47
|
"optional": true
|
|
40
48
|
}
|
|
41
49
|
},
|
|
42
|
-
"publishConfig": {
|
|
43
|
-
"access": "public",
|
|
44
|
-
"registry": "https://registry.npmjs.org/"
|
|
45
|
-
},
|
|
46
50
|
"scripts": {
|
|
47
51
|
"build": "rslib",
|
|
48
52
|
"dev": "rslib -w"
|