@rsbuild/plugin-react 2.0.0 → 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.
Files changed (3) hide show
  1. package/dist/index.d.ts +44 -44
  2. package/dist/index.js +18 -11
  3. package/package.json +20 -16
package/dist/index.d.ts CHANGED
@@ -1,52 +1,52 @@
1
- import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
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
  /**
5
- * Whether to enable split chunking for React-related dependencies (e.g., react, react-dom, scheduler).
6
- *
7
- * @default true
8
- */
9
- react?: boolean;
10
- /**
11
- * Whether to enable split chunking for routing-related dependencies (e.g., react-router, react-router-dom, history).
12
- *
13
- * @default true
14
- */
15
- router?: boolean;
5
+ * Whether to enable split chunking for React-related dependencies (e.g., react, react-dom, scheduler).
6
+ *
7
+ * @default true
8
+ */ react?: boolean;
9
+ /**
10
+ * Whether to enable split chunking for routing-related dependencies (e.g., react-router, react-router-dom, history).
11
+ *
12
+ * @default true
13
+ */ router?: boolean;
16
14
  };
15
+ export type ReactCompilerOptions = Exclude<NonNullable<Rspack.SwcLoaderTransformConfig['reactCompiler']>, boolean>;
17
16
  export type PluginReactOptions = {
18
17
  /**
19
- * Configure the behavior of SWC to transform React code,
20
- * the same as SWC's [jsc.transform.react](https://swc.rs/docs/configuration/compilation#jsctransformreact).
21
- */
22
- swcReactOptions?: Rspack.SwcLoaderTransformConfig['react'];
23
- /**
24
- * Configuration for chunk splitting of React-related dependencies when `chunkSplit.strategy`
25
- * is set to `split-by-experience`.
26
- * @default true
27
- */
28
- splitChunks?: boolean | SplitReactChunkOptions;
29
- /**
30
- * When set to `true`, enables the React Profiler for performance analysis in production builds.
31
- * @default false
32
- */
33
- enableProfiler?: boolean;
34
- /**
35
- * Options passed to `@rspack/plugin-react-refresh`
36
- * @default
37
- * {
38
- * include: [/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/],
39
- * exclude: [/[\\/]node_modules[\\/]/],
40
- * resourceQuery: { not: /^\?raw$/ },
41
- * }
42
- * @see https://rspack.rs/guide/tech/react#rspackplugin-react-refresh
43
- */
44
- reactRefreshOptions?: ReactRefreshOptions;
45
- /**
46
- * Whether to enable React Fast Refresh in development mode.
47
- * @default true
48
- */
49
- fastRefresh?: boolean;
18
+ * Configure the behavior of SWC to transform React code,
19
+ * the same as SWC's [jsc.transform.react](https://swc.rs/docs/configuration/compilation#jsctransformreact).
20
+ */ swcReactOptions?: Rspack.SwcLoaderTransformConfig['react'];
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
+ /**
28
+ * Configuration for chunk splitting of React-related dependencies when `chunkSplit.strategy`
29
+ * is set to `split-by-experience`.
30
+ * @default true
31
+ */ splitChunks?: boolean | SplitReactChunkOptions;
32
+ /**
33
+ * When set to `true`, enables the React Profiler for performance analysis in production builds.
34
+ * @default false
35
+ */ enableProfiler?: boolean;
36
+ /**
37
+ * Options passed to `@rspack/plugin-react-refresh`
38
+ * @default
39
+ * {
40
+ * include: [/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/],
41
+ * exclude: [/[\\/]node_modules[\\/]/],
42
+ * resourceQuery: { not: /^\?raw$/ },
43
+ * }
44
+ * @see https://rspack.rs/guide/tech/react#rspackplugin-react-refresh
45
+ */ reactRefreshOptions?: ReactRefreshOptions;
46
+ /**
47
+ * Whether to enable React Fast Refresh in development mode.
48
+ * @default true
49
+ */ fastRefresh?: boolean;
50
50
  };
51
- export declare const PLUGIN_REACT_NAME = "rsbuild:react";
51
+ export declare const PLUGIN_REACT_NAME = 'rsbuild:react';
52
52
  export declare const pluginReact: (options?: PluginReactOptions) => RsbuildPlugin;
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
- }, reactRefreshPath = finalOptions.fastRefresh ? src_require.resolve('react-refresh') : '';
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
- return mergeEnvironmentConfig({
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.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
- "license": "MIT",
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
- "types": "./dist/index.d.ts",
19
- "files": [
20
- "dist"
21
- ],
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org/"
29
+ },
22
30
  "dependencies": {
23
- "@rspack/plugin-react-refresh": "2.0.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.21.2",
29
- "@types/node": "^24.12.2",
36
+ "@rslib/core": "0.23.0",
37
+ "@types/node": "^24.13.2",
30
38
  "typescript": "^6.0.3",
31
- "@rsbuild/core": "2.0.0",
32
- "@scripts/test-helper": "1.0.0"
39
+ "@scripts/test-helper": "1.0.0",
40
+ "@rsbuild/core": "2.0.15"
33
41
  },
34
42
  "peerDependencies": {
35
- "@rsbuild/core": "^2.0.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"