@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,261 @@
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
+ applyInjectTags: function() {
14
+ return applyInjectTags;
15
+ },
16
+ builderPluginHtml: function() {
17
+ return builderPluginHtml;
18
+ }
19
+ });
20
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
21
+ const _shared = require("@rsbuild/shared");
22
+ const _lodash = /* @__PURE__ */ _interop_require_default(require("@modern-js/utils/lodash"));
23
+ function _interop_require_default(obj) {
24
+ return obj && obj.__esModule ? obj : {
25
+ default: obj
26
+ };
27
+ }
28
+ function _getRequireWildcardCache(nodeInterop) {
29
+ if (typeof WeakMap !== "function")
30
+ return null;
31
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
32
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
33
+ return (_getRequireWildcardCache = function(nodeInterop2) {
34
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
35
+ })(nodeInterop);
36
+ }
37
+ function _interop_require_wildcard(obj, nodeInterop) {
38
+ if (!nodeInterop && obj && obj.__esModule) {
39
+ return obj;
40
+ }
41
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
42
+ return {
43
+ default: obj
44
+ };
45
+ }
46
+ var cache = _getRequireWildcardCache(nodeInterop);
47
+ if (cache && cache.has(obj)) {
48
+ return cache.get(obj);
49
+ }
50
+ var newObj = {};
51
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
52
+ for (var key in obj) {
53
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
54
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
55
+ if (desc && (desc.get || desc.set)) {
56
+ Object.defineProperty(newObj, key, desc);
57
+ } else {
58
+ newObj[key] = obj[key];
59
+ }
60
+ }
61
+ }
62
+ newObj.default = obj;
63
+ if (cache) {
64
+ cache.set(obj, newObj);
65
+ }
66
+ return newObj;
67
+ }
68
+ async function getTemplateParameters(entryName, config, assetPrefix) {
69
+ const { applyOptionsChain } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
70
+ const { mountId, templateParameters, templateParametersByEntries } = config.html;
71
+ const meta = await (0, _shared.getMetaTags)(entryName, config);
72
+ const title = (0, _shared.getTitle)(entryName, config);
73
+ const templateParams = (templateParametersByEntries === null || templateParametersByEntries === void 0 ? void 0 : templateParametersByEntries[entryName]) || templateParameters;
74
+ const baseParameters = {
75
+ meta,
76
+ title,
77
+ mountId,
78
+ entryName,
79
+ assetPrefix
80
+ };
81
+ return (compilation, assets, assetTags, pluginOptions) => {
82
+ const defaultOptions = {
83
+ compilation,
84
+ webpackConfig: compilation.options,
85
+ htmlWebpackPlugin: {
86
+ tags: assetTags,
87
+ files: assets,
88
+ options: pluginOptions
89
+ },
90
+ ...baseParameters
91
+ };
92
+ return applyOptionsChain(defaultOptions, templateParams);
93
+ };
94
+ }
95
+ async function getChunks(entryName, entryValue) {
96
+ const { isPlainObject } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
97
+ const dependOn = [];
98
+ if (isPlainObject(entryValue)) {
99
+ dependOn.push(...entryValue.dependOn);
100
+ }
101
+ return [
102
+ ...dependOn,
103
+ entryName
104
+ ];
105
+ }
106
+ const applyInjectTags = (api) => {
107
+ api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID }) => {
108
+ const config = api.getNormalizedConfig();
109
+ const tags = _lodash.default.castArray(config.html.tags).filter(Boolean);
110
+ const tagsByEntries = _lodash.default.mapValues(config.html.tagsByEntries, (tags2) => _lodash.default.castArray(tags2).filter(Boolean));
111
+ const shouldByEntries = _lodash.default.some(tagsByEntries, "length");
112
+ if (!tags.length && !shouldByEntries) {
113
+ return;
114
+ }
115
+ const { HtmlTagsPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
116
+ const sharedOptions = {
117
+ HtmlPlugin,
118
+ append: true,
119
+ hash: false,
120
+ publicPath: true,
121
+ tags
122
+ };
123
+ if (tags.length && !shouldByEntries) {
124
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_TAGS).use(HtmlTagsPlugin, [
125
+ sharedOptions
126
+ ]);
127
+ return;
128
+ }
129
+ for (const [entry, filename] of Object.entries(api.getHTMLPaths())) {
130
+ const opts = {
131
+ ...sharedOptions,
132
+ includes: [
133
+ filename
134
+ ]
135
+ };
136
+ entry in tagsByEntries && (opts.tags = tagsByEntries[entry]);
137
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML_TAGS}#${entry}`).use(HtmlTagsPlugin, [
138
+ opts
139
+ ]);
140
+ }
141
+ });
142
+ };
143
+ const builderPluginHtml = () => ({
144
+ name: "builder-plugin-html",
145
+ setup(api) {
146
+ const routesInfo = [];
147
+ api.modifyBundlerChain(async (chain, { HtmlPlugin, isProd, CHAIN_ID, target }) => {
148
+ const config = api.getNormalizedConfig();
149
+ if ((0, _shared.isHtmlDisabled)(config, target)) {
150
+ return;
151
+ }
152
+ const { removeTailSlash, applyOptionsChain } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
153
+ const minify = await (0, _shared.getMinify)(isProd, config);
154
+ const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
155
+ const entries = chain.entryPoints.entries() || {};
156
+ const entryNames = Object.keys(entries);
157
+ const htmlPaths = api.getHTMLPaths();
158
+ const faviconUrls = [];
159
+ await Promise.all(entryNames.map(async (entryName, index) => {
160
+ const entryValue = entries[entryName].values();
161
+ const chunks = await getChunks(entryName, entryValue);
162
+ const inject = (0, _shared.getInject)(entryName, config);
163
+ const favicon = (0, _shared.getFavicon)(entryName, config);
164
+ const filename = htmlPaths[entryName];
165
+ const template = (0, _shared.getTemplatePath)(entryName, config);
166
+ const templateParameters = await getTemplateParameters(entryName, config, assetPrefix);
167
+ const pluginOptions = {
168
+ chunks,
169
+ inject,
170
+ minify,
171
+ filename,
172
+ template,
173
+ templateParameters,
174
+ scriptLoading: config.html.scriptLoading
175
+ };
176
+ if (favicon) {
177
+ if ((0, _shared.isURL)(favicon)) {
178
+ faviconUrls.push({
179
+ filename,
180
+ url: favicon
181
+ });
182
+ } else {
183
+ pluginOptions.favicon = favicon;
184
+ }
185
+ }
186
+ const finalOptions = applyOptionsChain(pluginOptions, config.tools.htmlPlugin, {
187
+ entryName,
188
+ entryValue
189
+ });
190
+ routesInfo.push({
191
+ urlPath: index === 0 ? "/" : `/${entryName}`,
192
+ entryName,
193
+ entryPath: filename,
194
+ isSPA: true
195
+ });
196
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [
197
+ finalOptions
198
+ ]);
199
+ }));
200
+ if (config.security) {
201
+ const { nonce } = config.security;
202
+ if (nonce) {
203
+ const { HtmlNoncePlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
204
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [
205
+ {
206
+ nonce,
207
+ HtmlPlugin
208
+ }
209
+ ]);
210
+ }
211
+ }
212
+ if (config.html) {
213
+ const { appIcon, crossorigin } = config.html;
214
+ if (crossorigin) {
215
+ const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
216
+ const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
217
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_CROSS_ORIGIN).use(HtmlCrossOriginPlugin, [
218
+ {
219
+ crossOrigin: formattedCrossorigin,
220
+ HtmlPlugin
221
+ }
222
+ ]);
223
+ chain.output.crossOriginLoading(formattedCrossorigin);
224
+ }
225
+ if (faviconUrls.length) {
226
+ const { HtmlFaviconUrlPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
227
+ chain.plugin(CHAIN_ID.PLUGIN.FAVICON_URL).use(HtmlFaviconUrlPlugin, [
228
+ {
229
+ faviconUrls,
230
+ HtmlPlugin
231
+ }
232
+ ]);
233
+ }
234
+ if (appIcon) {
235
+ const { HtmlAppIconPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
236
+ const distDir = (0, _shared.getDistPath)(config.output, "image");
237
+ const iconPath = _path.default.isAbsolute(appIcon) ? appIcon : _path.default.join(api.context.rootPath, appIcon);
238
+ chain.plugin(CHAIN_ID.PLUGIN.APP_ICON).use(HtmlAppIconPlugin, [
239
+ {
240
+ iconPath,
241
+ distDir,
242
+ HtmlPlugin
243
+ }
244
+ ]);
245
+ }
246
+ }
247
+ });
248
+ const emitRouteJson = async () => {
249
+ const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
250
+ const routeFilePath = _path.default.join(api.context.distPath, ROUTE_SPEC_FILE);
251
+ if (!await (0, _shared.isFileExists)(routeFilePath) && routesInfo.length) {
252
+ await fs.outputFile(routeFilePath, JSON.stringify({
253
+ routes: routesInfo
254
+ }, null, 2));
255
+ }
256
+ };
257
+ api.onBeforeBuild(emitRouteJson);
258
+ api.onBeforeStartDevServer(emitRouteJson);
259
+ applyInjectTags(api);
260
+ }
261
+ });
@@ -0,0 +1,2 @@
1
+ import { Plugins } from '@rsbuild/shared';
2
+ export declare const plugins: Plugins;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "plugins", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return plugins;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function")
14
+ return null;
15
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
16
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop2) {
18
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for (var key in obj) {
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ const plugins = {
53
+ html: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./html"))).then((m) => m.builderPluginHtml()),
54
+ cleanOutput: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./cleanOutput"))).then((m) => m.builderPluginCleanOutput()),
55
+ startUrl: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./startUrl"))).then((m) => m.builderPluginStartUrl()),
56
+ fileSize: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./fileSize"))).then((m) => m.builderPluginFileSize()),
57
+ devtool: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./devtool"))).then((m) => m.builderPluginDevtool()),
58
+ target: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./target"))).then((m) => m.builderPluginTarget()),
59
+ entry: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./entry"))).then((m) => m.builderPluginEntry()),
60
+ cache: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./cache"))).then((m) => m.builderPluginCache()),
61
+ yaml: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./yaml"))).then((m) => m.builderPluginYaml()),
62
+ toml: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./toml"))).then((m) => m.builderPluginToml()),
63
+ svg: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./svg"))).then((m) => m.builderPluginSvg()),
64
+ splitChunks: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./splitChunks"))).then((m) => m.builderPluginSplitChunks()),
65
+ inlineChunk: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./inlineChunk"))).then((m) => m.builderPluginInlineChunk()),
66
+ bundleAnalyzer: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./bundleAnalyzer"))).then((m) => m.builderPluginBundleAnalyzer()),
67
+ font: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./asset"))).then((m) => m.builderAssetPlugin("font", _shared.FONT_EXTENSIONS)),
68
+ image: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./asset"))).then((m) => m.builderAssetPlugin("image", _shared.IMAGE_EXTENSIONS)),
69
+ media: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./asset"))).then((m) => m.builderAssetPlugin("media", _shared.MEDIA_EXTENSIONS)),
70
+ assetsRetry: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./assetsRetry"))).then((m) => m.builderPluginAssetsRetry()),
71
+ antd: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./antd"))).then((m) => m.builderPluginAntd()),
72
+ arco: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./arco"))).then((m) => m.builderPluginArco()),
73
+ checkSyntax: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./checkSyntax"))).then((m) => m.builderPluginCheckSyntax()),
74
+ rem: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./rem"))).then((m) => m.builderPluginRem()),
75
+ wasm: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./wasm"))).then((m) => m.builderPluginWasm()),
76
+ moment: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./moment"))).then((m) => m.builderPluginMoment()),
77
+ nodeAddons: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./nodeAddons"))).then((m) => m.builderPluginNodeAddons()),
78
+ externals: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./externals"))).then((m) => m.builderPluginExternals()),
79
+ networkPerformance: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./networkPerformance"))).then((m) => m.builderPluginNetworkPerformance()),
80
+ preloadOrPrefetch: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./preloadOrPrefetch"))).then((m) => m.builderPluginPreloadOrPrefetch()),
81
+ performance: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./performance"))).then((m) => m.builderPluginPerformance()),
82
+ define: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("./define"))).then((m) => m.builderPluginDefine())
83
+ };
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginInlineChunk: () => DefaultBuilderPlugin;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginInlineChunk", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginInlineChunk;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function")
14
+ return null;
15
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
16
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop2) {
18
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for (var key in obj) {
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ const builderPluginInlineChunk = () => ({
53
+ name: "builder-plugin-inline-chunk",
54
+ setup(api) {
55
+ api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
56
+ const config = api.getNormalizedConfig();
57
+ if ((0, _shared.isHtmlDisabled)(config, target) || !isProd) {
58
+ return;
59
+ }
60
+ const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
61
+ const {
62
+ disableInlineRuntimeChunk,
63
+ enableInlineStyles,
64
+ // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
65
+ enableInlineScripts
66
+ } = config.output;
67
+ const scriptTests = [];
68
+ const styleTests = [];
69
+ if (enableInlineScripts) {
70
+ scriptTests.push(enableInlineScripts === true ? _shared.JS_REGEX : enableInlineScripts);
71
+ }
72
+ if (enableInlineStyles) {
73
+ styleTests.push(enableInlineStyles === true ? _shared.CSS_REGEX : enableInlineStyles);
74
+ }
75
+ if (!disableInlineRuntimeChunk) {
76
+ scriptTests.push(
77
+ // RegExp like /builder-runtime([.].+)?\.js$/
78
+ // matches builder-runtime.js and builder-runtime.123456.js
79
+ new RegExp(`${_shared.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`)
80
+ );
81
+ }
82
+ chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
83
+ HtmlPlugin,
84
+ {
85
+ styleTests,
86
+ scriptTests,
87
+ distPath: (0, _shared.pick)(config.output.distPath, [
88
+ "js",
89
+ "css"
90
+ ])
91
+ }
92
+ ]);
93
+ });
94
+ }
95
+ });
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginMoment: () => DefaultBuilderPlugin;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginMoment", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginMoment;
9
+ }
10
+ });
11
+ const builderPluginMoment = () => ({
12
+ name: "builder-plugin-moment",
13
+ setup(api) {
14
+ api.modifyBundlerChain(async (chain, { webpack }) => {
15
+ const config = api.getNormalizedConfig();
16
+ if (config.performance.removeMomentLocale) {
17
+ chain.plugin("remove-moment-locale").use(webpack.IgnorePlugin, [
18
+ {
19
+ resourceRegExp: /^\.\/locale$/,
20
+ contextRegExp: /moment$/
21
+ }
22
+ ]);
23
+ }
24
+ });
25
+ }
26
+ });
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginNetworkPerformance: () => DefaultBuilderPlugin;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginNetworkPerformance", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginNetworkPerformance;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ const builderPluginNetworkPerformance = () => ({
13
+ name: `builder-plugin-network-performance`,
14
+ setup(api) {
15
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker, HtmlPlugin }) => {
16
+ const config = api.getNormalizedConfig();
17
+ const { performance: { dnsPrefetch, preconnect } } = config;
18
+ if (isServer || isWebWorker || isServiceWorker) {
19
+ return;
20
+ }
21
+ if (dnsPrefetch) {
22
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(_shared.HtmlNetworkPerformancePlugin, [
23
+ dnsPrefetch,
24
+ "dnsPrefetch",
25
+ HtmlPlugin
26
+ ]);
27
+ }
28
+ if (preconnect) {
29
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(_shared.HtmlNetworkPerformancePlugin, [
30
+ preconnect,
31
+ "preconnect",
32
+ HtmlPlugin
33
+ ]);
34
+ }
35
+ });
36
+ }
37
+ });
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginNodeAddons: () => DefaultBuilderPlugin;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginNodeAddons", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginNodeAddons;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function")
14
+ return null;
15
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
16
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop2) {
18
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for (var key in obj) {
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ const builderPluginNodeAddons = () => ({
53
+ name: "builder-plugin-node-addons",
54
+ setup(api) {
55
+ api.modifyBundlerChain(async (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
56
+ if (!isServer && !isServiceWorker) {
57
+ return;
58
+ }
59
+ const { chalk, pkgUp } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
60
+ const getDistName = (resource) => {
61
+ const pkgJSON = pkgUp.sync({
62
+ cwd: resource
63
+ });
64
+ if (!pkgJSON) {
65
+ throw new Error(`Failed to compile Node.js addons, couldn't find the package.json of ${chalk.yellow(resource)}.`);
66
+ }
67
+ const getFilename = (resource2, pkgName2) => {
68
+ const reg = new RegExp(`node_modules/${pkgName2}/(.+)`);
69
+ const match = resource2.match(reg);
70
+ const filename = match === null || match === void 0 ? void 0 : match[1];
71
+ if (!filename) {
72
+ return "[name].[ext]";
73
+ }
74
+ return `${filename}`;
75
+ };
76
+ const { name: pkgName } = require(pkgJSON);
77
+ const config = api.getNormalizedConfig();
78
+ const serverPath = (0, _shared.getDistPath)(config.output, "server");
79
+ return `${serverPath}/${getFilename(resource, pkgName)}`;
80
+ };
81
+ chain.module.rule(CHAIN_ID.RULE.NODE).test(/\.node$/).use(CHAIN_ID.USE.NODE).loader((0, _shared.getSharedPkgCompiledPath)("node-loader")).options({
82
+ name: getDistName
83
+ });
84
+ });
85
+ }
86
+ });
@@ -0,0 +1,5 @@
1
+ import type { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ /**
3
+ * Apply some configs of builder performance
4
+ */
5
+ export declare const builderPluginPerformance: () => DefaultBuilderPlugin;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginPerformance", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginPerformance;
9
+ }
10
+ });
11
+ function applyProfile({ chain, config }) {
12
+ const { profile } = config.performance;
13
+ if (!profile) {
14
+ return;
15
+ }
16
+ chain.profile(profile);
17
+ }
18
+ const builderPluginPerformance = () => ({
19
+ name: "builder-plugin-performance",
20
+ setup(api) {
21
+ api.modifyBuilderConfig((builderConfig) => {
22
+ var _builderConfig_performance;
23
+ if ((_builderConfig_performance = builderConfig.performance) === null || _builderConfig_performance === void 0 ? void 0 : _builderConfig_performance.profile) {
24
+ var _builderConfig_performance1;
25
+ if (!((_builderConfig_performance1 = builderConfig.performance) === null || _builderConfig_performance1 === void 0 ? void 0 : _builderConfig_performance1.bundleAnalyze)) {
26
+ var _builderConfig;
27
+ var _performance;
28
+ (_performance = (_builderConfig = builderConfig).performance) !== null && _performance !== void 0 ? _performance : _builderConfig.performance = {};
29
+ builderConfig.performance.bundleAnalyze = {
30
+ analyzerMode: "disabled",
31
+ generateStatsFile: true
32
+ };
33
+ } else {
34
+ builderConfig.performance.bundleAnalyze = {
35
+ generateStatsFile: true,
36
+ ...builderConfig.performance.bundleAnalyze || {}
37
+ };
38
+ }
39
+ }
40
+ });
41
+ api.modifyBundlerChain((chain) => {
42
+ const config = api.getNormalizedConfig();
43
+ applyProfile({
44
+ chain,
45
+ config
46
+ });
47
+ });
48
+ }
49
+ });
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginPreloadOrPrefetch: () => DefaultBuilderPlugin;