@rsbuild/plugin-react 0.0.0-next-20231103091827

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ <p align="center">
2
+ <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
3
+ </p>
4
+
5
+ # Rsbuild
6
+
7
+ Unleash the power of Rspack with the out-of-the-box build tool.
8
+
9
+ ## Documentation
10
+
11
+ https://rsbuild.dev/
12
+
13
+ ## Contributing
14
+
15
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
16
+
17
+ ## License
18
+
19
+ Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
package/dist/antd.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { type SharedRsbuildPluginAPI } from '@rsbuild/shared';
2
+ export declare const applyAntdSupport: (api: SharedRsbuildPluginAPI) => void;
package/dist/antd.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var antd_exports = {};
20
+ __export(antd_exports, {
21
+ applyAntdSupport: () => applyAntdSupport
22
+ });
23
+ module.exports = __toCommonJS(antd_exports);
24
+ var import_shared = require("@rsbuild/shared");
25
+ const getAntdMajorVersion = (appDirectory) => {
26
+ try {
27
+ const pkgJsonPath = require.resolve("antd/package.json", {
28
+ paths: [appDirectory]
29
+ });
30
+ const { version } = require(pkgJsonPath);
31
+ return Number(version.split(".")[0]);
32
+ } catch (err) {
33
+ return null;
34
+ }
35
+ };
36
+ const applyAntdSupport = (api) => {
37
+ api.modifyRsbuildConfig((rsbuildConfig) => {
38
+ var _a, _b, _c;
39
+ (_a = rsbuildConfig.source) != null ? _a : rsbuildConfig.source = {};
40
+ if (rsbuildConfig.source.transformImport === false || ((_b = rsbuildConfig.source.transformImport) == null ? void 0 : _b.some(
41
+ (item) => item.libraryName === "antd"
42
+ ))) {
43
+ return;
44
+ }
45
+ const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
46
+ if (antdMajorVersion && antdMajorVersion < 5) {
47
+ (_c = rsbuildConfig.source) != null ? _c : rsbuildConfig.source = {};
48
+ rsbuildConfig.source.transformImport = [
49
+ ...rsbuildConfig.source.transformImport || [],
50
+ {
51
+ libraryName: "antd",
52
+ libraryDirectory: (0, import_shared.useSSR)(api.context.target) ? "lib" : "es",
53
+ style: true
54
+ }
55
+ ];
56
+ }
57
+ });
58
+ };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ applyAntdSupport
62
+ });
package/dist/arco.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { type SharedRsbuildPluginAPI } from '@rsbuild/shared';
2
+ export declare const applyArcoSupport: (api: SharedRsbuildPluginAPI) => void;
package/dist/arco.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var arco_exports = {};
20
+ __export(arco_exports, {
21
+ applyArcoSupport: () => applyArcoSupport
22
+ });
23
+ module.exports = __toCommonJS(arco_exports);
24
+ var import_shared = require("@rsbuild/shared");
25
+ const applyArcoSupport = (api) => {
26
+ const ARCO_NAME = "@arco-design/web-react";
27
+ const ARCO_ICON = `${ARCO_NAME}/icon`;
28
+ api.modifyRsbuildConfig((rsbuildConfig) => {
29
+ const { transformImport = [] } = rsbuildConfig.source || {};
30
+ if (transformImport === false || !(0, import_shared.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
31
+ return;
32
+ }
33
+ const isUseSSR = (0, import_shared.useSSR)(api.context.target);
34
+ if (!(transformImport == null ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
35
+ transformImport.push({
36
+ libraryName: ARCO_NAME,
37
+ libraryDirectory: isUseSSR ? "lib" : "es",
38
+ camelToDashComponentName: false,
39
+ style: true
40
+ });
41
+ }
42
+ if (!(transformImport == null ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
43
+ transformImport.push({
44
+ libraryName: ARCO_ICON,
45
+ libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
46
+ camelToDashComponentName: false
47
+ });
48
+ }
49
+ rsbuildConfig.source || (rsbuildConfig.source = {});
50
+ rsbuildConfig.source.transformImport = transformImport;
51
+ });
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ applyArcoSupport
56
+ });
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export declare const pluginReact: () => RsbuildPlugin;
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ pluginReact: () => pluginReact
22
+ });
23
+ module.exports = __toCommonJS(src_exports);
24
+ var import_antd = require("./antd");
25
+ var import_arco = require("./arco");
26
+ var import_splitChunks = require("./splitChunks");
27
+ var import_react = require("./react");
28
+ const pluginReact = () => ({
29
+ name: "plugin-react",
30
+ pre: ["plugin-swc"],
31
+ setup(api) {
32
+ if (api.context.bundlerType === "rspack") {
33
+ (0, import_react.applyBasicReactSupport)(api);
34
+ }
35
+ (0, import_antd.applyAntdSupport)(api);
36
+ (0, import_arco.applyArcoSupport)(api);
37
+ (0, import_splitChunks.applySplitChunksRule)(api);
38
+ }
39
+ });
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ pluginReact
43
+ });
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPluginAPI } from '@rsbuild/core/rspack-provider';
2
+ export declare const applyBasicReactSupport: (api: RsbuildPluginAPI) => void;
package/dist/react.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var react_exports = {};
30
+ __export(react_exports, {
31
+ applyBasicReactSupport: () => applyBasicReactSupport
32
+ });
33
+ module.exports = __toCommonJS(react_exports);
34
+ var import_shared = require("@rsbuild/shared");
35
+ function getReactRefreshEntry(compiler) {
36
+ var _a, _b, _c, _d, _e;
37
+ const hot = (_b = (_a = compiler.options.devServer) == null ? void 0 : _a.hot) != null ? _b : true;
38
+ const refresh = (_e = (_d = (_c = compiler.options.builtins) == null ? void 0 : _c.react) == null ? void 0 : _d.refresh) != null ? _e : true;
39
+ if (hot && refresh) {
40
+ const reactRefreshEntryPath = require.resolve("@rspack/plugin-react-refresh/react-refresh-entry");
41
+ return reactRefreshEntryPath;
42
+ }
43
+ return null;
44
+ }
45
+ const setupCompiler = (compiler) => {
46
+ if (!(0, import_shared.isClientCompiler)(compiler)) {
47
+ return;
48
+ }
49
+ const reactRefreshEntry = getReactRefreshEntry(compiler);
50
+ if (!reactRefreshEntry) {
51
+ return;
52
+ }
53
+ for (const key in compiler.options.entry) {
54
+ compiler.options.entry[key].import = [
55
+ reactRefreshEntry,
56
+ ...compiler.options.entry[key].import || []
57
+ ];
58
+ }
59
+ };
60
+ const applyBasicReactSupport = (api) => {
61
+ api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
62
+ if ((0, import_shared.isProd)()) {
63
+ return;
64
+ }
65
+ if (multiCompiler.compilers) {
66
+ multiCompiler.compilers.forEach(setupCompiler);
67
+ } else {
68
+ setupCompiler(multiCompiler);
69
+ }
70
+ });
71
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
72
+ const config = api.getNormalizedConfig();
73
+ const usingHMR = (0, import_shared.isUsingHMR)(config, { isProd: isProd2, target });
74
+ const rule = chain.module.rule(CHAIN_ID.RULE.JS);
75
+ const reactOptions = {
76
+ development: !isProd2,
77
+ refresh: usingHMR,
78
+ runtime: "automatic"
79
+ };
80
+ rule.use(CHAIN_ID.USE.SWC).tap((options) => {
81
+ options.jsc.transform.react = {
82
+ ...reactOptions
83
+ };
84
+ return options;
85
+ });
86
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
87
+ chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
88
+ options.jsc.transform.react = {
89
+ ...reactOptions
90
+ };
91
+ return options;
92
+ });
93
+ }
94
+ if (!usingHMR) {
95
+ return;
96
+ }
97
+ const { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(() => __toESM(require(
98
+ // TODO https://github.com/web-infra-dev/rspack/issues/4471
99
+ "@rspack/plugin-react-refresh"
100
+ )));
101
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
102
+ });
103
+ };
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ applyBasicReactSupport
107
+ });
@@ -0,0 +1,3 @@
1
+ import { type CacheGroup, type SharedRsbuildPluginAPI } from '@rsbuild/shared';
2
+ export declare function splitByExperience(rootPath: string): Promise<CacheGroup>;
3
+ export declare const applySplitChunksRule: (api: SharedRsbuildPluginAPI) => void;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var splitChunks_exports = {};
20
+ __export(splitChunks_exports, {
21
+ applySplitChunksRule: () => applySplitChunksRule,
22
+ splitByExperience: () => splitByExperience
23
+ });
24
+ module.exports = __toCommonJS(splitChunks_exports);
25
+ var import_splitChunks = require("@rsbuild/core/plugins/splitChunks");
26
+ var import_shared = require("@rsbuild/shared");
27
+ async function splitByExperience(rootPath) {
28
+ const experienceCacheGroup = {};
29
+ const packageRegExps = {
30
+ react: (0, import_splitChunks.createDependenciesRegExp)("react", "react-dom", "scheduler"),
31
+ router: (0, import_splitChunks.createDependenciesRegExp)(
32
+ "react-router",
33
+ "react-router-dom",
34
+ "@remix-run/router",
35
+ "history"
36
+ )
37
+ };
38
+ if ((0, import_shared.isPackageInstalled)("antd", rootPath)) {
39
+ packageRegExps.antd = (0, import_splitChunks.createDependenciesRegExp)("antd");
40
+ }
41
+ if ((0, import_shared.isPackageInstalled)("@arco-design/web-react", rootPath)) {
42
+ packageRegExps.arco = (0, import_splitChunks.createDependenciesRegExp)(/@?arco-design/);
43
+ }
44
+ if ((0, import_shared.isPackageInstalled)("@douyinfe/semi-ui", rootPath)) {
45
+ packageRegExps.semi = (0, import_splitChunks.createDependenciesRegExp)(
46
+ /@(ies|douyinfe)[\\/]semi-.*/
47
+ );
48
+ }
49
+ Object.entries(packageRegExps).forEach(([name, test]) => {
50
+ const key = `lib-${name}`;
51
+ experienceCacheGroup[key] = {
52
+ test,
53
+ priority: 0,
54
+ name: key,
55
+ reuseExistingChunk: true
56
+ };
57
+ });
58
+ return experienceCacheGroup;
59
+ }
60
+ const applySplitChunksRule = (api) => {
61
+ api.modifyRsbuildConfig(async (rsbuildConfig) => {
62
+ const { chunkSplit } = rsbuildConfig.performance || {};
63
+ if ((chunkSplit == null ? void 0 : chunkSplit.strategy) !== "split-by-experience") {
64
+ return;
65
+ }
66
+ const cacheGroups = await splitByExperience(api.context.rootPath);
67
+ const override = rsbuildConfig.performance.chunkSplit.override;
68
+ rsbuildConfig.performance.chunkSplit.override = {
69
+ cacheGroups: {
70
+ ...cacheGroups,
71
+ ...override ? override.cacheGroups : {}
72
+ },
73
+ ...override || {}
74
+ };
75
+ });
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ applySplitChunksRule,
80
+ splitByExperience
81
+ });
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@rsbuild/plugin-react",
3
+ "version": "0.0.0-next-20231103091827",
4
+ "description": "React plugin for Rsbuild",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/web-infra-dev/rsbuild",
8
+ "directory": "packages/plugin-react"
9
+ },
10
+ "license": "MIT",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "@rspack/plugin-react-refresh": "0.3.10",
24
+ "react-refresh": "^0.14.0",
25
+ "@rsbuild/shared": "0.0.0-next-20231103091827"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^16",
29
+ "typescript": "^5.2.2",
30
+ "@rsbuild/core": "0.0.0-next-20231103091827",
31
+ "@rsbuild/test-helper": "0.0.0-next-20231103091827"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "provenance": true,
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "scripts": {
39
+ "build": "modern build",
40
+ "dev": "modern build --watch"
41
+ }
42
+ }