@rsbuild/core 0.0.0-nightly-20231017024751

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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -0
  3. package/dist/createBuilder.d.ts +2 -0
  4. package/dist/createBuilder.js +51 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +21 -0
  7. package/dist/plugins/antd.d.ts +3 -0
  8. package/dist/plugins/antd.js +56 -0
  9. package/dist/plugins/arco.d.ts +2 -0
  10. package/dist/plugins/arco.js +44 -0
  11. package/dist/plugins/asset.d.ts +2 -0
  12. package/dist/plugins/asset.js +36 -0
  13. package/dist/plugins/assetsRetry.d.ts +2 -0
  14. package/dist/plugins/assetsRetry.js +77 -0
  15. package/dist/plugins/bundleAnalyzer.d.ts +2 -0
  16. package/dist/plugins/bundleAnalyzer.js +72 -0
  17. package/dist/plugins/cache.d.ts +2 -0
  18. package/dist/plugins/cache.js +147 -0
  19. package/dist/plugins/checkSyntax.d.ts +2 -0
  20. package/dist/plugins/checkSyntax.js +86 -0
  21. package/dist/plugins/cleanOutput.d.ts +2 -0
  22. package/dist/plugins/cleanOutput.js +65 -0
  23. package/dist/plugins/define.d.ts +2 -0
  24. package/dist/plugins/define.js +79 -0
  25. package/dist/plugins/devtool.d.ts +2 -0
  26. package/dist/plugins/devtool.js +26 -0
  27. package/dist/plugins/entry.d.ts +2 -0
  28. package/dist/plugins/entry.js +30 -0
  29. package/dist/plugins/externals.d.ts +2 -0
  30. package/dist/plugins/externals.js +31 -0
  31. package/dist/plugins/fileSize.d.ts +4 -0
  32. package/dist/plugins/fileSize.js +188 -0
  33. package/dist/plugins/html.d.ts +3 -0
  34. package/dist/plugins/html.js +261 -0
  35. package/dist/plugins/index.d.ts +2 -0
  36. package/dist/plugins/index.js +83 -0
  37. package/dist/plugins/inlineChunk.d.ts +2 -0
  38. package/dist/plugins/inlineChunk.js +95 -0
  39. package/dist/plugins/moment.d.ts +2 -0
  40. package/dist/plugins/moment.js +26 -0
  41. package/dist/plugins/networkPerformance.d.ts +2 -0
  42. package/dist/plugins/networkPerformance.js +37 -0
  43. package/dist/plugins/nodeAddons.d.ts +2 -0
  44. package/dist/plugins/nodeAddons.js +86 -0
  45. package/dist/plugins/performance.d.ts +5 -0
  46. package/dist/plugins/performance.js +49 -0
  47. package/dist/plugins/preloadOrPrefetch.d.ts +2 -0
  48. package/dist/plugins/preloadOrPrefetch.js +40 -0
  49. package/dist/plugins/rem.d.ts +2 -0
  50. package/dist/plugins/rem.js +124 -0
  51. package/dist/plugins/splitChunks.d.ts +4 -0
  52. package/dist/plugins/splitChunks.js +275 -0
  53. package/dist/plugins/startUrl.d.ts +3 -0
  54. package/dist/plugins/startUrl.js +111 -0
  55. package/dist/plugins/svg.d.ts +2 -0
  56. package/dist/plugins/svg.js +67 -0
  57. package/dist/plugins/target.d.ts +2 -0
  58. package/dist/plugins/target.js +56 -0
  59. package/dist/plugins/toml.d.ts +2 -0
  60. package/dist/plugins/toml.js +19 -0
  61. package/dist/plugins/wasm.d.ts +2 -0
  62. package/dist/plugins/wasm.js +34 -0
  63. package/dist/plugins/yaml.d.ts +2 -0
  64. package/dist/plugins/yaml.js +19 -0
  65. package/package.json +49 -0
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginPreloadOrPrefetch", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginPreloadOrPrefetch;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ const builderPluginPreloadOrPrefetch = () => ({
13
+ name: `builder-plugin-preload-or-prefetch`,
14
+ setup(api) {
15
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker, HtmlPlugin }) => {
16
+ const config = api.getNormalizedConfig();
17
+ const { performance: { preload, prefetch } } = config;
18
+ if (isServer || isWebWorker || isServiceWorker) {
19
+ return;
20
+ }
21
+ const HTMLCount = chain.entryPoints.values().length;
22
+ if (prefetch) {
23
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(_shared.HTMLPreloadOrPrefetchPlugin, [
24
+ prefetch,
25
+ "prefetch",
26
+ HtmlPlugin,
27
+ HTMLCount
28
+ ]);
29
+ }
30
+ if (preload) {
31
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(_shared.HTMLPreloadOrPrefetchPlugin, [
32
+ preload,
33
+ "preload",
34
+ HtmlPlugin,
35
+ HTMLCount
36
+ ]);
37
+ }
38
+ });
39
+ }
40
+ });
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginRem: () => DefaultBuilderPlugin;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginRem", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginRem;
9
+ }
10
+ });
11
+ const _lodash = /* @__PURE__ */ _interop_require_default(require("@modern-js/utils/lodash"));
12
+ const _shared = require("@rsbuild/shared");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ function _getRequireWildcardCache(nodeInterop) {
19
+ if (typeof WeakMap !== "function")
20
+ return null;
21
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
22
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
23
+ return (_getRequireWildcardCache = function(nodeInterop2) {
24
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
25
+ })(nodeInterop);
26
+ }
27
+ function _interop_require_wildcard(obj, nodeInterop) {
28
+ if (!nodeInterop && obj && obj.__esModule) {
29
+ return obj;
30
+ }
31
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
32
+ return {
33
+ default: obj
34
+ };
35
+ }
36
+ var cache = _getRequireWildcardCache(nodeInterop);
37
+ if (cache && cache.has(obj)) {
38
+ return cache.get(obj);
39
+ }
40
+ var newObj = {};
41
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
42
+ for (var key in obj) {
43
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
44
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
45
+ if (desc && (desc.get || desc.set)) {
46
+ Object.defineProperty(newObj, key, desc);
47
+ } else {
48
+ newObj[key] = obj[key];
49
+ }
50
+ }
51
+ }
52
+ newObj.default = obj;
53
+ if (cache) {
54
+ cache.set(obj, newObj);
55
+ }
56
+ return newObj;
57
+ }
58
+ const defaultOptions = {
59
+ enableRuntime: true,
60
+ rootFontSize: 50
61
+ };
62
+ const builderPluginRem = () => ({
63
+ name: "builder-plugin-rem",
64
+ pre: [
65
+ "builder-plugin-css",
66
+ "builder-plugin-less",
67
+ "builder-plugin-sass",
68
+ "builder-plugin-stylus"
69
+ ],
70
+ setup(api) {
71
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
72
+ const config = api.getNormalizedConfig();
73
+ const { output: { convertToRem } } = config;
74
+ if (!convertToRem || isServer || isWebWorker) {
75
+ return;
76
+ }
77
+ const userOptions = {
78
+ ...defaultOptions,
79
+ ...typeof convertToRem === "boolean" ? {} : convertToRem
80
+ };
81
+ const { default: PxToRemPlugin } = await Promise.resolve((0, _shared.getSharedPkgCompiledPath)("postcss-pxtorem")).then((p) => /* @__PURE__ */ _interop_require_wildcard(require(p)));
82
+ const applyRules = [
83
+ CHAIN_ID.RULE.CSS,
84
+ CHAIN_ID.RULE.LESS,
85
+ CHAIN_ID.RULE.SASS,
86
+ CHAIN_ID.RULE.STYLUS
87
+ ];
88
+ const getPxToRemPlugin = () => PxToRemPlugin({
89
+ rootValue: userOptions.rootFontSize,
90
+ unitPrecision: 5,
91
+ propList: [
92
+ "*"
93
+ ],
94
+ ..._lodash.default.cloneDeep(userOptions.pxtorem || {})
95
+ });
96
+ applyRules.forEach((name) => {
97
+ chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
98
+ var _options_postcssOptions;
99
+ return {
100
+ ...options,
101
+ postcssOptions: {
102
+ ...options.postcssOptions || {},
103
+ plugins: [
104
+ ...((_options_postcssOptions = options.postcssOptions) === null || _options_postcssOptions === void 0 ? void 0 : _options_postcssOptions.plugins) || [],
105
+ getPxToRemPlugin()
106
+ ]
107
+ }
108
+ };
109
+ });
110
+ });
111
+ if (!userOptions.enableRuntime) {
112
+ return;
113
+ }
114
+ const entries = Object.keys(chain.entryPoints.entries() || {});
115
+ const distDir = (0, _shared.getDistPath)(config.output, "js");
116
+ chain.plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE).use(_shared.AutoSetRootFontSizePlugin, [
117
+ userOptions,
118
+ entries,
119
+ HtmlPlugin,
120
+ distDir
121
+ ]);
122
+ });
123
+ }
124
+ });
@@ -0,0 +1,4 @@
1
+ import { type DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ /** Expect to match path just like "./node_modules/react-router/" */
3
+ export declare const createDependenciesRegExp: (...dependencies: (string | RegExp)[]) => RegExp;
4
+ export declare function builderPluginSplitChunks(): DefaultBuilderPlugin;
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ createDependenciesRegExp: function() {
14
+ return createDependenciesRegExp;
15
+ },
16
+ builderPluginSplitChunks: function() {
17
+ return builderPluginSplitChunks;
18
+ }
19
+ });
20
+ const _assert = /* @__PURE__ */ _interop_require_default(require("assert"));
21
+ const _shared = require("@rsbuild/shared");
22
+ function _interop_require_default(obj) {
23
+ return obj && obj.__esModule ? obj : {
24
+ default: obj
25
+ };
26
+ }
27
+ function _getRequireWildcardCache(nodeInterop) {
28
+ if (typeof WeakMap !== "function")
29
+ return null;
30
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
31
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
32
+ return (_getRequireWildcardCache = function(nodeInterop2) {
33
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
34
+ })(nodeInterop);
35
+ }
36
+ function _interop_require_wildcard(obj, nodeInterop) {
37
+ if (!nodeInterop && obj && obj.__esModule) {
38
+ return obj;
39
+ }
40
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
41
+ return {
42
+ default: obj
43
+ };
44
+ }
45
+ var cache = _getRequireWildcardCache(nodeInterop);
46
+ if (cache && cache.has(obj)) {
47
+ return cache.get(obj);
48
+ }
49
+ var newObj = {};
50
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
51
+ for (var key in obj) {
52
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
53
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
54
+ if (desc && (desc.get || desc.set)) {
55
+ Object.defineProperty(newObj, key, desc);
56
+ } else {
57
+ newObj[key] = obj[key];
58
+ }
59
+ }
60
+ }
61
+ newObj.default = obj;
62
+ if (cache) {
63
+ cache.set(obj, newObj);
64
+ }
65
+ return newObj;
66
+ }
67
+ function getUserDefinedCacheGroups(forceSplitting) {
68
+ const cacheGroups = {};
69
+ const pairs = Array.isArray(forceSplitting) ? forceSplitting.map((regexp, index) => [
70
+ `force-split-${index}`,
71
+ regexp
72
+ ]) : Object.entries(forceSplitting);
73
+ pairs.forEach(([key, regexp]) => {
74
+ cacheGroups[key] = {
75
+ test: regexp,
76
+ name: key,
77
+ chunks: "all",
78
+ // Ignore minimum size, minimum chunks and maximum requests and always create chunks for user defined cache group.
79
+ enforce: true
80
+ };
81
+ });
82
+ return cacheGroups;
83
+ }
84
+ const DEPENDENCY_MATCH_TEMPL = /[\\/]node_modules[\\/](<SOURCES>)[\\/]/.source;
85
+ const createDependenciesRegExp = (...dependencies) => {
86
+ const sources = dependencies.map((d) => typeof d === "string" ? d : d.source);
87
+ const expr = DEPENDENCY_MATCH_TEMPL.replace("<SOURCES>", sources.join("|"));
88
+ return new RegExp(expr);
89
+ };
90
+ async function splitByExperience(ctx) {
91
+ const { isPackageInstalled } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
92
+ const { override, polyfill, rootPath, defaultConfig, userDefinedCacheGroups } = ctx;
93
+ const experienceCacheGroup = {};
94
+ const packageRegExps = {
95
+ react: createDependenciesRegExp("react", "react-dom", "scheduler"),
96
+ router: createDependenciesRegExp("react-router", "react-router-dom", "@remix-run/router", "history"),
97
+ lodash: createDependenciesRegExp("lodash", "lodash-es"),
98
+ axios: createDependenciesRegExp("axios", /axios-.+/)
99
+ };
100
+ if (isPackageInstalled("antd", rootPath)) {
101
+ packageRegExps.antd = createDependenciesRegExp("antd");
102
+ }
103
+ if (isPackageInstalled("@arco-design/web-react", rootPath)) {
104
+ packageRegExps.arco = createDependenciesRegExp(/@?arco-design/);
105
+ }
106
+ if (isPackageInstalled("@douyinfe/semi-ui", rootPath)) {
107
+ packageRegExps.semi = createDependenciesRegExp(/@(ies|douyinfe)[\\/]semi-.*/);
108
+ }
109
+ if (polyfill === "entry" || polyfill === "usage") {
110
+ packageRegExps.polyfill = createDependenciesRegExp("tslib", "core-js", "@babel/runtime", "@swc/helpers");
111
+ }
112
+ Object.entries(packageRegExps).forEach(([name, test]) => {
113
+ const key = `lib-${name}`;
114
+ experienceCacheGroup[key] = {
115
+ test,
116
+ priority: 0,
117
+ name: key,
118
+ reuseExistingChunk: true
119
+ };
120
+ });
121
+ (0, _assert.default)(defaultConfig !== false);
122
+ (0, _assert.default)(override !== false);
123
+ return {
124
+ ...defaultConfig,
125
+ ...override,
126
+ cacheGroups: {
127
+ ...defaultConfig.cacheGroups,
128
+ ...experienceCacheGroup,
129
+ ...userDefinedCacheGroups,
130
+ ...override.cacheGroups
131
+ }
132
+ };
133
+ }
134
+ function splitByModule(ctx) {
135
+ const { override, userDefinedCacheGroups, defaultConfig } = ctx;
136
+ (0, _assert.default)(defaultConfig !== false);
137
+ (0, _assert.default)(override !== false);
138
+ return {
139
+ ...defaultConfig,
140
+ minSize: 0,
141
+ maxInitialRequests: Infinity,
142
+ ...override,
143
+ cacheGroups: {
144
+ ...defaultConfig.cacheGroups,
145
+ ...userDefinedCacheGroups,
146
+ // Core group
147
+ vendors: {
148
+ priority: -10,
149
+ test: _shared.NODE_MODULES_REGEX,
150
+ // todo: not support in rspack
151
+ name(module) {
152
+ return (0, _shared.getPackageNameFromModulePath)(module.context);
153
+ }
154
+ },
155
+ ...override.cacheGroups
156
+ }
157
+ };
158
+ }
159
+ function splitBySize(ctx) {
160
+ const { override, userDefinedCacheGroups, defaultConfig, builderConfig } = ctx;
161
+ (0, _assert.default)(defaultConfig !== false);
162
+ (0, _assert.default)(override !== false);
163
+ (0, _assert.default)(builderConfig.strategy === "split-by-size");
164
+ var _builderConfig_minSize, _builderConfig_maxSize;
165
+ return {
166
+ ...defaultConfig,
167
+ minSize: (_builderConfig_minSize = builderConfig.minSize) !== null && _builderConfig_minSize !== void 0 ? _builderConfig_minSize : 0,
168
+ maxSize: (_builderConfig_maxSize = builderConfig.maxSize) !== null && _builderConfig_maxSize !== void 0 ? _builderConfig_maxSize : Infinity,
169
+ ...override,
170
+ cacheGroups: {
171
+ ...defaultConfig.cacheGroups,
172
+ ...userDefinedCacheGroups,
173
+ ...override.cacheGroups
174
+ }
175
+ };
176
+ }
177
+ function splitCustom(ctx) {
178
+ const { override, userDefinedCacheGroups, defaultConfig } = ctx;
179
+ (0, _assert.default)(defaultConfig !== false);
180
+ (0, _assert.default)(override !== false);
181
+ return {
182
+ ...defaultConfig,
183
+ ...override,
184
+ cacheGroups: {
185
+ ...defaultConfig.cacheGroups,
186
+ ...userDefinedCacheGroups,
187
+ ...override.cacheGroups
188
+ }
189
+ };
190
+ }
191
+ function allInOne(_ctx) {
192
+ return false;
193
+ }
194
+ function singleVendor(ctx) {
195
+ const { override, defaultConfig, userDefinedCacheGroups } = ctx;
196
+ (0, _assert.default)(defaultConfig !== false);
197
+ (0, _assert.default)(override !== false);
198
+ const singleVendorCacheGroup = {
199
+ singleVendor: {
200
+ test: _shared.NODE_MODULES_REGEX,
201
+ priority: 0,
202
+ chunks: "all",
203
+ name: "vendor",
204
+ enforce: true,
205
+ reuseExistingChunk: true
206
+ }
207
+ };
208
+ return {
209
+ ...defaultConfig,
210
+ ...override,
211
+ cacheGroups: {
212
+ ...defaultConfig.cacheGroups,
213
+ ...singleVendorCacheGroup,
214
+ ...userDefinedCacheGroups,
215
+ ...override.cacheGroups
216
+ }
217
+ };
218
+ }
219
+ const SPLIT_STRATEGY_DISPATCHER = {
220
+ "split-by-experience": splitByExperience,
221
+ "split-by-module": splitByModule,
222
+ "split-by-size": splitBySize,
223
+ custom: splitCustom,
224
+ "all-in-one": allInOne,
225
+ "single-vendor": singleVendor
226
+ };
227
+ function builderPluginSplitChunks() {
228
+ return {
229
+ name: "builder-plugin-split-chunks",
230
+ setup(api) {
231
+ api.modifyBundlerChain(async (chain, { isServer, isWebWorker, isServiceWorker }) => {
232
+ if (isServer || isWebWorker || isServiceWorker) {
233
+ chain.optimization.splitChunks(false);
234
+ if (isWebWorker || isServiceWorker) {
235
+ chain.module.parser.merge({
236
+ javascript: {
237
+ dynamicImportMode: "eager"
238
+ }
239
+ });
240
+ }
241
+ return;
242
+ }
243
+ const config = api.getNormalizedConfig();
244
+ const defaultConfig = {
245
+ // Optimize both `initial` and `async` chunks
246
+ chunks: "all",
247
+ // When chunk size >= 50000 bytes, split it into separate chunk
248
+ enforceSizeThreshold: 5e4,
249
+ cacheGroups: {}
250
+ };
251
+ const { chunkSplit } = config.performance;
252
+ let userDefinedCacheGroups = {};
253
+ if (chunkSplit.forceSplitting) {
254
+ userDefinedCacheGroups = getUserDefinedCacheGroups(chunkSplit.forceSplitting);
255
+ }
256
+ var _chunkSplit_splitChunks;
257
+ const override = chunkSplit.strategy === "custom" ? (_chunkSplit_splitChunks = chunkSplit.splitChunks) !== null && _chunkSplit_splitChunks !== void 0 ? _chunkSplit_splitChunks : chunkSplit.override : chunkSplit.override;
258
+ const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
259
+ defaultConfig,
260
+ override: override || {},
261
+ userDefinedCacheGroups,
262
+ builderConfig: chunkSplit,
263
+ rootPath: api.context.rootPath,
264
+ polyfill: config.output.polyfill
265
+ });
266
+ chain.optimization.splitChunks(splitChunksOptions);
267
+ if (chunkSplit.strategy !== "all-in-one") {
268
+ chain.optimization.runtimeChunk({
269
+ name: _shared.RUNTIME_CHUNK_NAME
270
+ });
271
+ }
272
+ });
273
+ }
274
+ };
275
+ }
@@ -0,0 +1,3 @@
1
+ import type { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const replacePlaceholder: (url: string, port: number) => string;
3
+ export declare function builderPluginStartUrl(): DefaultBuilderPlugin;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ replacePlaceholder: function() {
14
+ return replacePlaceholder;
15
+ },
16
+ builderPluginStartUrl: function() {
17
+ return builderPluginStartUrl;
18
+ }
19
+ });
20
+ const _lodash = /* @__PURE__ */ _interop_require_default(require("@modern-js/utils/lodash"));
21
+ function _interop_require_default(obj) {
22
+ return obj && obj.__esModule ? obj : {
23
+ default: obj
24
+ };
25
+ }
26
+ function _getRequireWildcardCache(nodeInterop) {
27
+ if (typeof WeakMap !== "function")
28
+ return null;
29
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
30
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
31
+ return (_getRequireWildcardCache = function(nodeInterop2) {
32
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
33
+ })(nodeInterop);
34
+ }
35
+ function _interop_require_wildcard(obj, nodeInterop) {
36
+ if (!nodeInterop && obj && obj.__esModule) {
37
+ return obj;
38
+ }
39
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
40
+ return {
41
+ default: obj
42
+ };
43
+ }
44
+ var cache = _getRequireWildcardCache(nodeInterop);
45
+ if (cache && cache.has(obj)) {
46
+ return cache.get(obj);
47
+ }
48
+ var newObj = {};
49
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
50
+ for (var key in obj) {
51
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
52
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
53
+ if (desc && (desc.get || desc.set)) {
54
+ Object.defineProperty(newObj, key, desc);
55
+ } else {
56
+ newObj[key] = obj[key];
57
+ }
58
+ }
59
+ }
60
+ newObj.default = obj;
61
+ if (cache) {
62
+ cache.set(obj, newObj);
63
+ }
64
+ return newObj;
65
+ }
66
+ const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
67
+ const openedURLs = [];
68
+ function builderPluginStartUrl() {
69
+ return {
70
+ name: "builder-plugin-start-url",
71
+ async setup(api) {
72
+ let port;
73
+ api.onAfterStartDevServer(async (params) => {
74
+ ({ port } = params);
75
+ });
76
+ api.onDevCompileDone(async ({ isFirstCompile }) => {
77
+ if (!isFirstCompile || !port) {
78
+ return;
79
+ }
80
+ const config = api.getNormalizedConfig();
81
+ const { startUrl, beforeStartUrl } = config.dev;
82
+ const { https } = api.context.devServer || {};
83
+ if (!startUrl) {
84
+ return;
85
+ }
86
+ const urls = [];
87
+ if (startUrl === true) {
88
+ const protocol = https ? "https" : "http";
89
+ urls.push(`${protocol}://localhost:${port}`);
90
+ } else {
91
+ urls.push(..._lodash.default.castArray(startUrl).map((item) => replacePlaceholder(item, port)));
92
+ }
93
+ const { ensureArray } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
94
+ const { openBrowser } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
95
+ const openUrls = () => {
96
+ for (const url of urls) {
97
+ if (!openedURLs.includes(url)) {
98
+ openBrowser(url);
99
+ openedURLs.push(url);
100
+ }
101
+ }
102
+ };
103
+ if (beforeStartUrl) {
104
+ Promise.all(ensureArray(beforeStartUrl).map((fn) => fn())).then(openUrls);
105
+ } else {
106
+ openUrls();
107
+ }
108
+ });
109
+ }
110
+ };
111
+ }
@@ -0,0 +1,2 @@
1
+ import type { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginSvg: () => DefaultBuilderPlugin;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginSvg", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginSvg;
9
+ }
10
+ });
11
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
12
+ const _shared = require("@rsbuild/shared");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const builderPluginSvg = () => {
19
+ return {
20
+ name: "builder-plugin-svg",
21
+ setup(api) {
22
+ api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
23
+ const config = api.getNormalizedConfig();
24
+ const defaultExport = config.output.svgDefaultExport;
25
+ const assetType = "svg";
26
+ const distDir = (0, _shared.getDistPath)(config.output, "svg");
27
+ const filename = (0, _shared.getFilename)(config.output, "svg", isProd);
28
+ const outputName = _path.default.posix.join(distDir, filename);
29
+ const maxSize = config.output.dataUriLimit[assetType];
30
+ const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(_shared.SVG_REGEX);
31
+ if (config.output.disableSvgr) {
32
+ (0, _shared.chainStaticAssetRule)({
33
+ rule,
34
+ maxSize,
35
+ filename: _path.default.posix.join(distDir, filename),
36
+ assetType
37
+ });
38
+ return;
39
+ }
40
+ (0, _shared.chainStaticAssetRule)({
41
+ rule,
42
+ maxSize,
43
+ filename: _path.default.posix.join(distDir, filename),
44
+ assetType,
45
+ issuer: {
46
+ // The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
47
+ not: [
48
+ _shared.JS_REGEX,
49
+ _shared.TS_REGEX
50
+ ]
51
+ }
52
+ });
53
+ rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type("asset/inline").resourceQuery(/inline/);
54
+ rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type("asset/resource").resourceQuery(/url/).set("generator", {
55
+ filename: outputName
56
+ });
57
+ rule.oneOf(CHAIN_ID.ONE_OF.SVG).type("javascript/auto").use(CHAIN_ID.USE.SVGR).loader(require.resolve("@svgr/webpack")).options({
58
+ svgo: true,
59
+ svgoConfig: (0, _shared.getSvgoDefaultConfig)()
60
+ }).end().when(defaultExport === "url", (c) => c.use(CHAIN_ID.USE.URL).loader((0, _shared.getSharedPkgCompiledPath)("url-loader")).options({
61
+ limit: config.output.dataUriLimit.svg,
62
+ name: outputName
63
+ }));
64
+ });
65
+ }
66
+ };
67
+ };
@@ -0,0 +1,2 @@
1
+ import type { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginTarget: () => DefaultBuilderPlugin;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginTarget", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginTarget;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ const builderPluginTarget = () => ({
13
+ name: "builder-plugin-target",
14
+ setup(api) {
15
+ api.modifyBundlerChain(async (chain, { target }) => {
16
+ if (target === "node") {
17
+ chain.target("node");
18
+ return;
19
+ }
20
+ if (target === "service-worker") {
21
+ chain.target("webworker");
22
+ return;
23
+ }
24
+ if (target === "web-worker") {
25
+ chain.target([
26
+ "webworker",
27
+ "es5"
28
+ ]);
29
+ return;
30
+ }
31
+ const browserslist = await (0, _shared.getBrowserslist)(api.context.rootPath);
32
+ if (browserslist) {
33
+ chain.merge({
34
+ target: [
35
+ "web",
36
+ "browserslist"
37
+ ]
38
+ });
39
+ } else if (target === "modern-web") {
40
+ chain.merge({
41
+ target: [
42
+ "web",
43
+ "es2015"
44
+ ]
45
+ });
46
+ } else {
47
+ chain.merge({
48
+ target: [
49
+ "web",
50
+ "es5"
51
+ ]
52
+ });
53
+ }
54
+ });
55
+ }
56
+ });