@rsbuild/plugin-react 0.0.0-nightly-20231024161008

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,3 @@
1
+ import type { RsbuildTarget, SharedRsbuildPluginAPI } from '@rsbuild/shared';
2
+ export declare const applyAntdSupport: (api: SharedRsbuildPluginAPI) => void;
3
+ export declare function useSSR(target: RsbuildTarget | RsbuildTarget[]): boolean;
package/dist/antd.js ADDED
@@ -0,0 +1,58 @@
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
+ useSSR: () => useSSR
23
+ });
24
+ module.exports = __toCommonJS(antd_exports);
25
+ var import_utils = require("@modern-js/utils");
26
+ const applyAntdSupport = (api) => {
27
+ api.modifyRsbuildConfig((rsbuildConfig) => {
28
+ var _a, _b, _c;
29
+ (_a = rsbuildConfig.source) != null ? _a : rsbuildConfig.source = {};
30
+ if (rsbuildConfig.source.transformImport === false || ((_b = rsbuildConfig.source.transformImport) == null ? void 0 : _b.some(
31
+ (item) => item.libraryName === "antd"
32
+ ))) {
33
+ return;
34
+ }
35
+ const antdMajorVersion = (0, import_utils.getAntdMajorVersion)(api.context.rootPath);
36
+ if (antdMajorVersion && antdMajorVersion < 5) {
37
+ (_c = rsbuildConfig.source) != null ? _c : rsbuildConfig.source = {};
38
+ rsbuildConfig.source.transformImport = [
39
+ ...rsbuildConfig.source.transformImport || [],
40
+ {
41
+ libraryName: "antd",
42
+ libraryDirectory: useSSR(api.context.target) ? "lib" : "es",
43
+ style: true
44
+ }
45
+ ];
46
+ }
47
+ });
48
+ };
49
+ function useSSR(target) {
50
+ return (Array.isArray(target) ? target : [target]).some(
51
+ (item) => ["node", "service-worker"].includes(item)
52
+ );
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ applyAntdSupport,
57
+ useSSR
58
+ });
package/dist/arco.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { SharedRsbuildPluginAPI } from '@rsbuild/shared';
2
+ export declare const applyArcoSupport: (api: SharedRsbuildPluginAPI) => void;
package/dist/arco.js ADDED
@@ -0,0 +1,57 @@
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_utils = require("@modern-js/utils");
25
+ var import_antd = require("./antd");
26
+ const applyArcoSupport = (api) => {
27
+ const ARCO_NAME = "@arco-design/web-react";
28
+ const ARCO_ICON = `${ARCO_NAME}/icon`;
29
+ api.modifyRsbuildConfig((rsbuildConfig) => {
30
+ const { transformImport = [] } = rsbuildConfig.source || {};
31
+ if (transformImport === false || !(0, import_utils.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
32
+ return;
33
+ }
34
+ const isUseSSR = (0, import_antd.useSSR)(api.context.target);
35
+ if (!(transformImport == null ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
36
+ transformImport.push({
37
+ libraryName: ARCO_NAME,
38
+ libraryDirectory: isUseSSR ? "lib" : "es",
39
+ camelToDashComponentName: false,
40
+ style: true
41
+ });
42
+ }
43
+ if (!(transformImport == null ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
44
+ transformImport.push({
45
+ libraryName: ARCO_ICON,
46
+ libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
47
+ camelToDashComponentName: false
48
+ });
49
+ }
50
+ rsbuildConfig.source || (rsbuildConfig.source = {});
51
+ rsbuildConfig.source.transformImport = transformImport;
52
+ });
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ applyArcoSupport
57
+ });
@@ -0,0 +1,2 @@
1
+ import { DefaultRsbuildPlugin } from '@rsbuild/shared';
2
+ export declare const pluginReact: () => DefaultRsbuildPlugin;
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
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
+ (0, import_react.applyBasicReactSupport)(api);
33
+ (0, import_antd.applyAntdSupport)(api);
34
+ (0, import_arco.applyArcoSupport)(api);
35
+ (0, import_splitChunks.applySplitChunksRule)(api);
36
+ }
37
+ });
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ pluginReact
41
+ });
@@ -0,0 +1,2 @@
1
+ import { SharedRsbuildPluginAPI } from '@rsbuild/shared';
2
+ export declare const applyBasicReactSupport: (api: SharedRsbuildPluginAPI) => void;
package/dist/react.js ADDED
@@ -0,0 +1,130 @@
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
+ const applyRspack = (api) => {
36
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
37
+ const config = api.getNormalizedConfig();
38
+ const usingHMR = (0, import_shared.isUsingHMR)(config, { isProd: isProd2, target });
39
+ const rule = chain.module.rule(CHAIN_ID.RULE.JS);
40
+ const reactOptions = {
41
+ development: !isProd2,
42
+ refresh: usingHMR,
43
+ runtime: "automatic"
44
+ };
45
+ rule.use(CHAIN_ID.USE.SWC).tap((options) => {
46
+ options.jsc.transform.react = {
47
+ ...reactOptions
48
+ };
49
+ return options;
50
+ });
51
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
52
+ chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
53
+ options.jsc.transform.react = {
54
+ ...reactOptions
55
+ };
56
+ return options;
57
+ });
58
+ }
59
+ if (!usingHMR) {
60
+ return;
61
+ }
62
+ const { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(() => __toESM(require(
63
+ // @ts-expect-error
64
+ "@rspack/plugin-react-refresh"
65
+ )));
66
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
67
+ });
68
+ };
69
+ const applyWebpack = (api) => {
70
+ api.modifyRsbuildConfig(async (config, { mergeRsbuildConfig }) => {
71
+ const { isBeyondReact17 } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
72
+ const babelConfig = {
73
+ tools: {
74
+ babel(_, { addPresets, addPlugins }) {
75
+ const isNewJsx = isBeyondReact17(api.context.rootPath);
76
+ const presetReactOptions = {
77
+ development: !(0, import_shared.isProd)(),
78
+ // Will use the native built-in instead of trying to polyfill
79
+ useBuiltIns: true,
80
+ useSpread: false,
81
+ runtime: isNewJsx ? "automatic" : "classic"
82
+ };
83
+ addPresets([
84
+ [require.resolve("@babel/preset-react"), presetReactOptions]
85
+ ]);
86
+ if ((0, import_shared.isProd)()) {
87
+ addPlugins([
88
+ [
89
+ require.resolve("babel-plugin-transform-react-remove-prop-types"),
90
+ { removeImport: true }
91
+ ]
92
+ ]);
93
+ }
94
+ }
95
+ }
96
+ };
97
+ return mergeRsbuildConfig(babelConfig, config);
98
+ });
99
+ api.modifyWebpackChain(async (chain, utils) => {
100
+ const config = api.getNormalizedConfig();
101
+ if (!(0, import_shared.isUsingHMR)(config, utils)) {
102
+ return;
103
+ }
104
+ const { CHAIN_ID } = utils;
105
+ const { default: ReactFastRefreshPlugin } = await Promise.resolve().then(() => __toESM(require("@pmmmwh/react-refresh-webpack-plugin")));
106
+ const useTsLoader = Boolean(config.tools.tsLoader);
107
+ const rule = useTsLoader ? chain.module.rule(CHAIN_ID.RULE.TS) : chain.module.rule(CHAIN_ID.RULE.JS);
108
+ rule.use(CHAIN_ID.USE.BABEL).tap((options) => ({
109
+ ...options,
110
+ plugins: [
111
+ ...options.plugins || [],
112
+ [require.resolve("react-refresh/babel"), { skipEnvCheck: true }]
113
+ ]
114
+ }));
115
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactFastRefreshPlugin, [
116
+ {
117
+ overlay: false,
118
+ exclude: [/node_modules/]
119
+ }
120
+ ]);
121
+ });
122
+ };
123
+ const applyBasicReactSupport = (api) => {
124
+ const { bundlerType } = api.context;
125
+ bundlerType === "rspack" ? applyRspack(api) : applyWebpack(api);
126
+ };
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ applyBasicReactSupport
130
+ });
@@ -0,0 +1,3 @@
1
+ import { type SharedRsbuildPluginAPI, type CacheGroup } from '@rsbuild/shared';
2
+ export declare function splitByExperience(rootPath: string): Promise<CacheGroup>;
3
+ export declare const applySplitChunksRule: (api: SharedRsbuildPluginAPI) => void;
@@ -0,0 +1,91 @@
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 splitChunks_exports = {};
30
+ __export(splitChunks_exports, {
31
+ applySplitChunksRule: () => applySplitChunksRule,
32
+ splitByExperience: () => splitByExperience
33
+ });
34
+ module.exports = __toCommonJS(splitChunks_exports);
35
+ var import_splitChunks = require("@rsbuild/core/plugins/splitChunks");
36
+ async function splitByExperience(rootPath) {
37
+ const { isPackageInstalled } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
38
+ const experienceCacheGroup = {};
39
+ const packageRegExps = {
40
+ react: (0, import_splitChunks.createDependenciesRegExp)("react", "react-dom", "scheduler"),
41
+ router: (0, import_splitChunks.createDependenciesRegExp)(
42
+ "react-router",
43
+ "react-router-dom",
44
+ "@remix-run/router",
45
+ "history"
46
+ )
47
+ };
48
+ if (isPackageInstalled("antd", rootPath)) {
49
+ packageRegExps.antd = (0, import_splitChunks.createDependenciesRegExp)("antd");
50
+ }
51
+ if (isPackageInstalled("@arco-design/web-react", rootPath)) {
52
+ packageRegExps.arco = (0, import_splitChunks.createDependenciesRegExp)(/@?arco-design/);
53
+ }
54
+ if (isPackageInstalled("@douyinfe/semi-ui", rootPath)) {
55
+ packageRegExps.semi = (0, import_splitChunks.createDependenciesRegExp)(
56
+ /@(ies|douyinfe)[\\/]semi-.*/
57
+ );
58
+ }
59
+ Object.entries(packageRegExps).forEach(([name, test]) => {
60
+ const key = `lib-${name}`;
61
+ experienceCacheGroup[key] = {
62
+ test,
63
+ priority: 0,
64
+ name: key,
65
+ reuseExistingChunk: true
66
+ };
67
+ });
68
+ return experienceCacheGroup;
69
+ }
70
+ const applySplitChunksRule = (api) => {
71
+ api.modifyRsbuildConfig(async (rsbuildConfig) => {
72
+ const { chunkSplit } = rsbuildConfig.performance || {};
73
+ if ((chunkSplit == null ? void 0 : chunkSplit.strategy) !== "split-by-experience") {
74
+ return;
75
+ }
76
+ const cacheGroups = await splitByExperience(api.context.rootPath);
77
+ const override = rsbuildConfig.performance.chunkSplit.override;
78
+ rsbuildConfig.performance.chunkSplit.override = {
79
+ cacheGroups: {
80
+ ...cacheGroups,
81
+ ...override ? override.cacheGroups : {}
82
+ },
83
+ ...override || {}
84
+ };
85
+ });
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ applySplitChunksRule,
90
+ splitByExperience
91
+ });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@rsbuild/plugin-react",
3
+ "version": "0.0.0-nightly-20231024161008",
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
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "@rspack/plugin-react-refresh": "0.3.8",
24
+ "@babel/preset-react": "^7.22.15",
25
+ "@modern-js/utils": "^2.37.1",
26
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
27
+ "babel-plugin-transform-react-remove-prop-types": "0.4.24",
28
+ "@rsbuild/shared": "0.0.0-nightly-20231024161008"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^16",
32
+ "typescript": "^5",
33
+ "@rsbuild/core": "0.0.0-nightly-20231024161008",
34
+ "@rsbuild/test-helper": "0.0.0-nightly-20231024161008",
35
+ "@rsbuild/webpack": "0.0.0-nightly-20231024161008"
36
+ },
37
+ "publishConfig": {
38
+ "registry": "https://registry.npmjs.org/",
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "scripts": {
43
+ "dev": "modern build --watch",
44
+ "build": "modern build"
45
+ }
46
+ }