@rsbuild/core 0.3.0 → 0.3.2

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 (39) hide show
  1. package/dist/cli/commands.js +1 -1
  2. package/dist/cli/prepare.js +1 -1
  3. package/dist/client/formatStats.d.ts +12 -0
  4. package/dist/client/formatStats.js +94 -0
  5. package/dist/client/hmr.js +58 -172
  6. package/dist/constants.d.ts +6 -0
  7. package/dist/constants.js +43 -0
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +14 -1
  10. package/dist/plugins/moment.js +6 -0
  11. package/dist/provider/core/build.d.ts +1 -1
  12. package/dist/provider/core/createCompiler.js +1 -1
  13. package/dist/provider/core/createContext.d.ts +1 -1
  14. package/dist/provider/core/createContext.js +1 -1
  15. package/dist/provider/css-modules-typescript-pre-loader/index.d.ts +1 -1
  16. package/dist/provider/index.d.ts +1 -0
  17. package/dist/provider/index.js +3 -0
  18. package/dist/provider/plugins/swc.js +2 -1
  19. package/dist/provider/shared.d.ts +9 -1
  20. package/dist/provider/shared.js +35 -0
  21. package/dist/rspack/HtmlAppIconPlugin.js +8 -0
  22. package/dist/rspack/HtmlBasicPlugin.js +7 -0
  23. package/dist/rspack/HtmlCrossOriginPlugin.js +7 -0
  24. package/dist/rspack/HtmlNetworkPerformancePlugin.js +7 -0
  25. package/dist/rspack/HtmlNoncePlugin.js +7 -0
  26. package/dist/rspack/HtmlTagsPlugin.js +8 -2
  27. package/dist/rspack/InlineChunkHtmlPlugin.js +10 -0
  28. package/dist/rspack/RemoveCssSourcemapPlugin.js +6 -0
  29. package/dist/rspack/preload/HtmlPreloadOrPrefetchPlugin.js +9 -1
  30. package/dist/rspack/preload/helpers/doesChunkBelongToHtml.d.ts +1 -1
  31. package/dist/rspack/preload/helpers/extractChunks.d.ts +1 -1
  32. package/dist/server/compilerDevMiddleware.js +10 -0
  33. package/dist/server/devServer.d.ts +1 -1
  34. package/dist/server/helper.d.ts +1 -1
  35. package/dist/server/helper.js +44 -26
  36. package/dist/server/middlewares.js +4 -3
  37. package/dist/server/prodServer.js +8 -1
  38. package/dist/server/socketServer.js +10 -2
  39. package/package.json +2 -2
@@ -86,7 +86,7 @@ async function init({
86
86
  }
87
87
  }
88
88
  function runCli() {
89
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.0");
89
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.2");
90
90
  import_commander.program.command("dev").option("-o --open [url]", "open the page in browser on startup").option(
91
91
  "--port <port>",
92
92
  "specify a port number for Rsbuild Server to listen"
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.3.0"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.3.2"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file at
6
+ * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
+ */
8
+ import type { StatsCompilation } from 'webpack';
9
+ export declare function formatStatsMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
10
+ errors: string[];
11
+ warnings: string[];
12
+ };
@@ -0,0 +1,94 @@
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 formatStats_exports = {};
20
+ __export(formatStats_exports, {
21
+ formatStatsMessages: () => formatStatsMessages
22
+ });
23
+ module.exports = __toCommonJS(formatStats_exports);
24
+ const friendlySyntaxErrorLabel = "SyntaxError:";
25
+ function isLikelyASyntaxError(message) {
26
+ return message.includes(friendlySyntaxErrorLabel);
27
+ }
28
+ function formatMessage(stats) {
29
+ let lines = [];
30
+ let message;
31
+ if (typeof stats === "object") {
32
+ const fileName = stats.moduleName ? `File: ${stats.moduleName}
33
+ ` : "";
34
+ const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
35
+ const details = stats.details ? `
36
+ Details: ${stats.details}
37
+ ` : "";
38
+ const stack = stats.stack ? `
39
+ ${stats.stack}` : "";
40
+ message = `${fileName}${mainMessage}${details}${stack}`;
41
+ } else {
42
+ message = stats;
43
+ }
44
+ lines = message.split("\n");
45
+ lines = lines.map((line) => {
46
+ const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
47
+ line
48
+ );
49
+ if (!parsingError) {
50
+ return line;
51
+ }
52
+ const [, errorLine, errorColumn, errorMessage] = parsingError;
53
+ return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
54
+ });
55
+ message = lines.join("\n");
56
+ message = message.replace(
57
+ /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
58
+ `${friendlySyntaxErrorLabel} $3 ($1:$2)
59
+ `
60
+ );
61
+ lines = message.split("\n");
62
+ if (lines.length > 2 && lines[1].trim() === "") {
63
+ lines.splice(1, 1);
64
+ }
65
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
66
+ if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
67
+ lines[1] = lines[1].replace("Error: ", "");
68
+ }
69
+ lines = lines.filter(
70
+ (line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
71
+ );
72
+ message = lines.join("\n");
73
+ return message.trim();
74
+ }
75
+ function formatStatsMessages(json) {
76
+ const formattedErrors = json?.errors?.map(formatMessage);
77
+ const formattedWarnings = json?.warnings?.map(formatMessage);
78
+ const result = {
79
+ errors: formattedErrors || [],
80
+ warnings: formattedWarnings || [],
81
+ errorTips: []
82
+ };
83
+ if (result.errors?.some(isLikelyASyntaxError)) {
84
+ result.errors = result.errors.filter(isLikelyASyntaxError);
85
+ }
86
+ if (result.errors.length > 1) {
87
+ result.errors.length = 1;
88
+ }
89
+ return result;
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ formatStatsMessages
94
+ });
@@ -169,179 +169,65 @@ function _ts_generator(thisArg, body) {
169
169
  };
170
170
  }
171
171
  }
172
- var __create = Object.create;
173
- var __defProp = Object.defineProperty;
174
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
175
- var __getOwnPropNames = Object.getOwnPropertyNames;
176
- var __getProtoOf = Object.getPrototypeOf;
177
- var __hasOwnProp = Object.prototype.hasOwnProperty;
178
- var __commonJS = function(cb, mod) {
179
- return function __require() {
180
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
181
- exports: {}
182
- }).exports, mod), mod.exports;
183
- };
184
- };
185
- var __copyProps = function(to, from, except, desc) {
186
- if (from && typeof from === "object" || typeof from === "function") {
187
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
188
- try {
189
- var _loop = function() {
190
- var key = _step.value;
191
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
192
- get: function() {
193
- return from[key];
194
- },
195
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
196
- });
197
- };
198
- for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
199
- } catch (err) {
200
- _didIteratorError = true;
201
- _iteratorError = err;
202
- } finally{
203
- try {
204
- if (!_iteratorNormalCompletion && _iterator.return != null) {
205
- _iterator.return();
206
- }
207
- } finally{
208
- if (_didIteratorError) {
209
- throw _iteratorError;
210
- }
211
- }
212
- }
172
+ // src/client/formatStats.ts
173
+ var friendlySyntaxErrorLabel = "SyntaxError:";
174
+ function isLikelyASyntaxError(message) {
175
+ return message.includes(friendlySyntaxErrorLabel);
176
+ }
177
+ function formatMessage(stats) {
178
+ var lines = [];
179
+ var message;
180
+ if (typeof stats === "object") {
181
+ var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
182
+ var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
183
+ var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
184
+ var stack = stats.stack ? "\n".concat(stats.stack) : "";
185
+ message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
186
+ } else {
187
+ message = stats;
213
188
  }
214
- return to;
215
- };
216
- var __toESM = function(mod, isNodeMode, target) {
217
- return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
218
- // file that has been converted to a CommonJS file using a Babel-
219
- // compatible transform (i.e. "__esModule" has not been set), then set
220
- // "default" to the CommonJS "module.exports" for node compatibility.
221
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
222
- value: mod,
223
- enumerable: true
224
- }) : target, mod);
225
- };
226
- // ../shared/dist/formatStats.js
227
- var require_formatStats = __commonJS({
228
- "../shared/dist/formatStats.js": function(exports2, module2) {
229
- "use strict";
230
- var __defProp2 = Object.defineProperty;
231
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
232
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
233
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
234
- var __export = function(target, all) {
235
- for(var name in all)__defProp2(target, name, {
236
- get: all[name],
237
- enumerable: true
238
- });
239
- };
240
- var __copyProps2 = function(to, from, except, desc) {
241
- if (from && typeof from === "object" || typeof from === "function") {
242
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
243
- try {
244
- var _loop = function() {
245
- var key = _step.value;
246
- if (!__hasOwnProp2.call(to, key) && key !== except) __defProp2(to, key, {
247
- get: function() {
248
- return from[key];
249
- },
250
- enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
251
- });
252
- };
253
- for(var _iterator = __getOwnPropNames2(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
254
- } catch (err) {
255
- _didIteratorError = true;
256
- _iteratorError = err;
257
- } finally{
258
- try {
259
- if (!_iteratorNormalCompletion && _iterator.return != null) {
260
- _iterator.return();
261
- }
262
- } finally{
263
- if (_didIteratorError) {
264
- throw _iteratorError;
265
- }
266
- }
267
- }
268
- }
269
- return to;
270
- };
271
- var __toCommonJS = function(mod) {
272
- return __copyProps2(__defProp2({}, "__esModule", {
273
- value: true
274
- }), mod);
275
- };
276
- var formatStats_exports = {};
277
- __export(formatStats_exports, {
278
- formatStatsMessages: function() {
279
- return formatStatsMessages2;
280
- }
281
- });
282
- module2.exports = __toCommonJS(formatStats_exports);
283
- var friendlySyntaxErrorLabel = "SyntaxError:";
284
- function isLikelyASyntaxError(message) {
285
- return message.includes(friendlySyntaxErrorLabel);
286
- }
287
- function formatMessage(stats) {
288
- var lines = [];
289
- var message;
290
- if (typeof stats === "object") {
291
- var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
292
- var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
293
- var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
294
- var stack = stats.stack ? "\n".concat(stats.stack) : "";
295
- message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
296
- } else {
297
- message = stats;
298
- }
299
- lines = message.split("\n");
300
- lines = lines.map(function(line) {
301
- var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
302
- if (!parsingError) {
303
- return line;
304
- }
305
- var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
306
- return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
307
- });
308
- message = lines.join("\n");
309
- message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
310
- lines = message.split("\n");
311
- if (lines.length > 2 && lines[1].trim() === "") {
312
- lines.splice(1, 1);
313
- }
314
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
315
- if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
316
- lines[1] = lines[1].replace("Error: ", "");
317
- }
318
- lines = lines.filter(function(line, index, arr) {
319
- return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
320
- });
321
- message = lines.join("\n");
322
- return message.trim();
323
- }
324
- function formatStatsMessages2(json) {
325
- var _json_errors, _json_warnings, _result_errors;
326
- var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
327
- var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
328
- var result = {
329
- errors: formattedErrors || [],
330
- warnings: formattedWarnings || [],
331
- errorTips: []
332
- };
333
- if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
334
- result.errors = result.errors.filter(isLikelyASyntaxError);
335
- }
336
- if (result.errors.length > 1) {
337
- result.errors.length = 1;
338
- }
339
- return result;
189
+ lines = message.split("\n");
190
+ lines = lines.map(function(line) {
191
+ var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
192
+ if (!parsingError) {
193
+ return line;
340
194
  }
195
+ var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
196
+ return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
197
+ });
198
+ message = lines.join("\n");
199
+ message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
200
+ lines = message.split("\n");
201
+ if (lines.length > 2 && lines[1].trim() === "") {
202
+ lines.splice(1, 1);
341
203
  }
342
- });
343
- // src/client/hmr/index.ts
344
- var import_format_stats = __toESM(require_formatStats());
204
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
205
+ if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
206
+ lines[1] = lines[1].replace("Error: ", "");
207
+ }
208
+ lines = lines.filter(function(line, index, arr) {
209
+ return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
210
+ });
211
+ message = lines.join("\n");
212
+ return message.trim();
213
+ }
214
+ function formatStatsMessages(json) {
215
+ var _json_errors, _json_warnings, _result_errors;
216
+ var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
217
+ var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
218
+ var result = {
219
+ errors: formattedErrors || [],
220
+ warnings: formattedWarnings || [],
221
+ errorTips: []
222
+ };
223
+ if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
224
+ result.errors = result.errors.filter(isLikelyASyntaxError);
225
+ }
226
+ if (result.errors.length > 1) {
227
+ result.errors.length = 1;
228
+ }
229
+ return result;
230
+ }
345
231
  // src/client/hmr/createSocketUrl.ts
346
232
  var HMR_SOCK_PATH = "/rsbuild-hmr";
347
233
  function createSocketUrl(resourceQuery) {
@@ -420,7 +306,7 @@ function handleWarnings(warnings) {
420
306
  isFirstCompilation = false;
421
307
  hasCompileErrors = false;
422
308
  function printWarnings() {
423
- var formatted = (0, import_format_stats.formatStatsMessages)({
309
+ var formatted = formatStatsMessages({
424
310
  warnings: warnings,
425
311
  errors: []
426
312
  });
@@ -443,7 +329,7 @@ function handleErrors(errors) {
443
329
  clearOutdatedErrors();
444
330
  isFirstCompilation = false;
445
331
  hasCompileErrors = true;
446
- var formatted = (0, import_format_stats.formatStatsMessages)({
332
+ var formatted = formatStatsMessages({
447
333
  errors: errors,
448
334
  warnings: []
449
335
  });
@@ -0,0 +1,6 @@
1
+ export declare const PLUGIN_SWC_NAME = "rsbuild:swc";
2
+ export declare const PLUGIN_CSS_NAME = "rsbuild:css";
3
+ export declare const PLUGIN_LESS_NAME = "rsbuild:less";
4
+ export declare const PLUGIN_SASS_NAME = "rsbuild:sass";
5
+ export declare const PLUGIN_BABEL_NAME = "rsbuild:babel";
6
+ export declare const PLUGIN_STYLUS_NAME = "rsbuild:stylus";
@@ -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 constants_exports = {};
20
+ __export(constants_exports, {
21
+ PLUGIN_BABEL_NAME: () => PLUGIN_BABEL_NAME,
22
+ PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
23
+ PLUGIN_LESS_NAME: () => PLUGIN_LESS_NAME,
24
+ PLUGIN_SASS_NAME: () => PLUGIN_SASS_NAME,
25
+ PLUGIN_STYLUS_NAME: () => PLUGIN_STYLUS_NAME,
26
+ PLUGIN_SWC_NAME: () => PLUGIN_SWC_NAME
27
+ });
28
+ module.exports = __toCommonJS(constants_exports);
29
+ const PLUGIN_SWC_NAME = "rsbuild:swc";
30
+ const PLUGIN_CSS_NAME = "rsbuild:css";
31
+ const PLUGIN_LESS_NAME = "rsbuild:less";
32
+ const PLUGIN_SASS_NAME = "rsbuild:sass";
33
+ const PLUGIN_BABEL_NAME = "rsbuild:babel";
34
+ const PLUGIN_STYLUS_NAME = "rsbuild:stylus";
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ PLUGIN_BABEL_NAME,
38
+ PLUGIN_CSS_NAME,
39
+ PLUGIN_LESS_NAME,
40
+ PLUGIN_SASS_NAME,
41
+ PLUGIN_STYLUS_NAME,
42
+ PLUGIN_SWC_NAME
43
+ });
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { createRsbuild } from './createRsbuild';
7
7
  export { loadConfig, defineConfig } from './cli/config';
8
8
  export declare const version: any;
9
9
  export { logger, mergeRsbuildConfig } from '@rsbuild/shared';
10
+ export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, PLUGIN_SASS_NAME, PLUGIN_LESS_NAME, PLUGIN_BABEL_NAME, PLUGIN_STYLUS_NAME, } from './constants';
10
11
  export type { Rspack } from './provider';
11
- export type { RsbuildConfig, NormalizedConfig, RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI, } from './types';
12
+ export type { RsbuildConfig, DevConfig, HtmlConfig, ToolsConfig, SourceConfig, OutputConfig, SecurityConfig, PerformanceConfig, NormalizedConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedToolsConfig, NormalizedSourceConfig, NormalizedOutputConfig, NormalizedSecurityConfig, NormalizedPerformanceConfig, RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI, } from './types';
12
13
  export type { RsbuildMode, RsbuildEntry, RsbuildTarget, RsbuildContext, RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, } from '@rsbuild/shared';
package/dist/index.js CHANGED
@@ -18,6 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
+ PLUGIN_BABEL_NAME: () => import_constants.PLUGIN_BABEL_NAME,
22
+ PLUGIN_CSS_NAME: () => import_constants.PLUGIN_CSS_NAME,
23
+ PLUGIN_LESS_NAME: () => import_constants.PLUGIN_LESS_NAME,
24
+ PLUGIN_SASS_NAME: () => import_constants.PLUGIN_SASS_NAME,
25
+ PLUGIN_STYLUS_NAME: () => import_constants.PLUGIN_STYLUS_NAME,
26
+ PLUGIN_SWC_NAME: () => import_constants.PLUGIN_SWC_NAME,
21
27
  createRsbuild: () => import_createRsbuild.createRsbuild,
22
28
  defineConfig: () => import_config.defineConfig,
23
29
  loadConfig: () => import_config.loadConfig,
@@ -31,9 +37,16 @@ var import_loadEnv = require("./loadEnv");
31
37
  var import_createRsbuild = require("./createRsbuild");
32
38
  var import_config = require("./cli/config");
33
39
  var import_shared = require("@rsbuild/shared");
34
- const version = "0.3.0";
40
+ var import_constants = require("./constants");
41
+ const version = "0.3.2";
35
42
  // Annotate the CommonJS export names for ESM import in node:
36
43
  0 && (module.exports = {
44
+ PLUGIN_BABEL_NAME,
45
+ PLUGIN_CSS_NAME,
46
+ PLUGIN_LESS_NAME,
47
+ PLUGIN_SASS_NAME,
48
+ PLUGIN_STYLUS_NAME,
49
+ PLUGIN_SWC_NAME,
37
50
  createRsbuild,
38
51
  defineConfig,
39
52
  loadConfig,
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var moment_exports = {};
20
25
  __export(moment_exports, {
21
26
  pluginMoment: () => pluginMoment
@@ -23,6 +28,7 @@ __export(moment_exports, {
23
28
  module.exports = __toCommonJS(moment_exports);
24
29
  class IgnorePlugin {
25
30
  constructor(options) {
31
+ __publicField(this, "options");
26
32
  this.options = options;
27
33
  this.checkIgnore = this.checkIgnore.bind(this);
28
34
  }
@@ -1,3 +1,3 @@
1
- import { InitConfigsOptions } from './initConfigs';
1
+ import { type InitConfigsOptions } from './initConfigs';
2
2
  import type { BuildOptions } from '@rsbuild/shared';
3
3
  export declare const build: (initOptions: InitConfigsOptions, { mode, watch, compiler: customCompiler }?: BuildOptions) => Promise<void>;
@@ -93,7 +93,7 @@ async function createCompiler({
93
93
  printTime(obj, 0);
94
94
  }
95
95
  }
96
- const { message, level } = (0, import_shared.formatStats)(stats);
96
+ const { message, level } = (0, import_shared2.formatStats)(stats);
97
97
  if (level === "error") {
98
98
  import_shared.logger.error(message);
99
99
  }
@@ -1,4 +1,4 @@
1
- import { RsbuildConfig, type BundlerType, type RsbuildContext, type NormalizedConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
1
+ import { type BundlerType, type RsbuildConfig, type RsbuildContext, type NormalizedConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
2
2
  import type { InternalContext } from '../../types';
3
3
  /**
4
4
  * Create context by config.
@@ -59,7 +59,7 @@ function createContextByConfig(options, bundlerType, config = {}) {
59
59
  const context = {
60
60
  entry: config.source?.entry || getDefaultEntry(rootPath),
61
61
  targets: config.output?.targets || [],
62
- version: "0.3.0",
62
+ version: "0.3.2",
63
63
  rootPath,
64
64
  distPath,
65
65
  cachePath,
@@ -1,4 +1,4 @@
1
- import { CssModules } from '@rsbuild/shared';
1
+ import { type CssModules } from '@rsbuild/shared';
2
2
  import type { LoaderContext } from '@rspack/core';
3
3
  export default function (this: LoaderContext<{
4
4
  modules: Required<CssModules>;
@@ -9,3 +9,4 @@ export { getPluginAPI } from './core/initPlugins';
9
9
  export { applyBaseCSSRule, applyCSSModuleRule } from './plugins/css';
10
10
  export type { InternalContext } from '../types';
11
11
  export { setHTMLPlugin, getHTMLPlugin } from './htmlPluginUtil';
12
+ export { formatStats } from './shared';
@@ -22,6 +22,7 @@ __export(provider_exports, {
22
22
  applyCSSModuleRule: () => import_css.applyCSSModuleRule,
23
23
  createContext: () => import_createContext.createContext,
24
24
  createPublicContext: () => import_createContext.createPublicContext,
25
+ formatStats: () => import_shared2.formatStats,
25
26
  getHTMLPlugin: () => import_htmlPluginUtil.getHTMLPlugin,
26
27
  getPluginAPI: () => import_initPlugins.getPluginAPI,
27
28
  initHooks: () => import_initHooks.initHooks,
@@ -41,12 +42,14 @@ var import_initConfigs = require("./core/initConfigs");
41
42
  var import_initPlugins = require("./core/initPlugins");
42
43
  var import_css = require("./plugins/css");
43
44
  var import_htmlPluginUtil = require("./htmlPluginUtil");
45
+ var import_shared2 = require("./shared");
44
46
  // Annotate the CommonJS export names for ESM import in node:
45
47
  0 && (module.exports = {
46
48
  applyBaseCSSRule,
47
49
  applyCSSModuleRule,
48
50
  createContext,
49
51
  createPublicContext,
52
+ formatStats,
50
53
  getHTMLPlugin,
51
54
  getPluginAPI,
52
55
  initHooks,
@@ -34,6 +34,7 @@ __export(swc_exports, {
34
34
  module.exports = __toCommonJS(swc_exports);
35
35
  var import_shared = require("@rsbuild/shared");
36
36
  var import_path = __toESM(require("path"));
37
+ var import_constants = require("../../constants");
37
38
  const builtinSwcLoaderName = "builtin:swc-loader";
38
39
  async function getDefaultSwcConfig(config, rootPath, target) {
39
40
  return {
@@ -56,7 +57,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
56
57
  };
57
58
  }
58
59
  const pluginSwc = () => ({
59
- name: "rsbuild:swc",
60
+ name: import_constants.PLUGIN_SWC_NAME,
60
61
  setup(api) {
61
62
  api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
62
63
  const config = api.getNormalizedConfig();
@@ -1,7 +1,15 @@
1
- import { RsbuildPlugin } from '../types';
1
+ import { type Stats, type MultiStats } from '@rsbuild/shared';
2
+ import type { RsbuildPlugin } from '../types';
2
3
  import { type Plugins } from '@rsbuild/shared';
3
4
  export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
4
5
  export declare const rspackMinVersion = "0.5.0";
5
6
  export declare const isSatisfyRspackVersion: (originalVersion: string) => Promise<boolean>;
6
7
  export declare const getCompiledPath: (packageName: string) => string;
7
8
  export declare const BUILTIN_LOADER = "builtin:";
9
+ export declare function formatStats(stats: Stats | MultiStats, showWarnings?: boolean): {
10
+ message: string;
11
+ level: string;
12
+ } | {
13
+ message?: undefined;
14
+ level?: undefined;
15
+ };
@@ -30,6 +30,7 @@ var shared_exports = {};
30
30
  __export(shared_exports, {
31
31
  BUILTIN_LOADER: () => BUILTIN_LOADER,
32
32
  applyDefaultPlugins: () => applyDefaultPlugins,
33
+ formatStats: () => formatStats,
33
34
  getCompiledPath: () => getCompiledPath,
34
35
  isSatisfyRspackVersion: () => isSatisfyRspackVersion,
35
36
  rspackMinVersion: () => rspackMinVersion
@@ -39,6 +40,7 @@ var import_path = require("path");
39
40
  var import_shared = require("@rsbuild/shared");
40
41
  var import_shared2 = require("@rsbuild/shared");
41
42
  var import_shared3 = require("@rsbuild/shared");
43
+ var import_formatStats = require("../client/formatStats");
42
44
  const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
43
45
  Promise.resolve().then(() => __toESM(require("./plugins/transition"))).then((m) => m.pluginTransition()),
44
46
  plugins.basic(),
@@ -108,10 +110,43 @@ const getCompiledPath = (packageName) => {
108
110
  return (0, import_shared.getSharedPkgCompiledPath)(packageName);
109
111
  };
110
112
  const BUILTIN_LOADER = "builtin:";
113
+ function formatStats(stats, showWarnings = true) {
114
+ const statsData = stats.toJson({
115
+ preset: "errors-warnings"
116
+ });
117
+ const { errors, warnings } = (0, import_formatStats.formatStatsMessages)(statsData);
118
+ if (errors.length) {
119
+ const errorMsgs = `${errors.join("\n\n")}
120
+ `;
121
+ const isTerserError = errorMsgs.includes("from Terser");
122
+ const title = import_shared.color.bold(
123
+ import_shared.color.red(isTerserError ? "Minify error: " : "Compile error: ")
124
+ );
125
+ const tip = import_shared.color.yellow(
126
+ isTerserError ? "Failed to minify with terser, check for syntax errors." : "Failed to compile, check the errors for troubleshooting."
127
+ );
128
+ return {
129
+ message: `${title}
130
+ ${tip}
131
+ ${errorMsgs}`,
132
+ level: "error"
133
+ };
134
+ }
135
+ if (warnings.length && (showWarnings || process.stdout.isTTY)) {
136
+ const title = import_shared.color.bold(import_shared.color.yellow("Compile Warning: \n"));
137
+ return {
138
+ message: `${title}${`${warnings.join("\n\n")}
139
+ `}`,
140
+ level: "warning"
141
+ };
142
+ }
143
+ return {};
144
+ }
111
145
  // Annotate the CommonJS export names for ESM import in node:
112
146
  0 && (module.exports = {
113
147
  BUILTIN_LOADER,
114
148
  applyDefaultPlugins,
149
+ formatStats,
115
150
  getCompiledPath,
116
151
  isSatisfyRspackVersion,
117
152
  rspackMinVersion
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
  var HtmlAppIconPlugin_exports = {};
30
35
  __export(HtmlAppIconPlugin_exports, {
31
36
  HtmlAppIconPlugin: () => HtmlAppIconPlugin
@@ -38,6 +43,9 @@ var import_shared = require("@rsbuild/shared");
38
43
  var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
39
44
  class HtmlAppIconPlugin {
40
45
  constructor(options) {
46
+ __publicField(this, "name");
47
+ __publicField(this, "distDir");
48
+ __publicField(this, "iconPath");
41
49
  this.name = "HtmlAppIconPlugin";
42
50
  this.distDir = options.distDir;
43
51
  this.iconPath = options.iconPath;
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var HtmlBasicPlugin_exports = {};
20
25
  __export(HtmlBasicPlugin_exports, {
21
26
  HtmlBasicPlugin: () => HtmlBasicPlugin,
@@ -26,6 +31,8 @@ var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
26
31
  const hasTitle = (html) => html ? /<title/i.test(html) && /<\/title/i.test(html) : false;
27
32
  class HtmlBasicPlugin {
28
33
  constructor(options) {
34
+ __publicField(this, "name");
35
+ __publicField(this, "options");
29
36
  this.name = "HtmlBasicPlugin";
30
37
  this.options = options;
31
38
  }
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var HtmlCrossOriginPlugin_exports = {};
20
25
  __export(HtmlCrossOriginPlugin_exports, {
21
26
  HtmlCrossOriginPlugin: () => HtmlCrossOriginPlugin
@@ -24,6 +29,8 @@ module.exports = __toCommonJS(HtmlCrossOriginPlugin_exports);
24
29
  var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
25
30
  class HtmlCrossOriginPlugin {
26
31
  constructor(options) {
32
+ __publicField(this, "name");
33
+ __publicField(this, "crossOrigin");
27
34
  const { crossOrigin } = options;
28
35
  this.name = "HtmlCrossOriginPlugin";
29
36
  this.crossOrigin = crossOrigin;
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var HtmlNetworkPerformancePlugin_exports = {};
20
25
  __export(HtmlNetworkPerformancePlugin_exports, {
21
26
  HtmlNetworkPerformancePlugin: () => HtmlNetworkPerformancePlugin
@@ -40,6 +45,8 @@ function generateLinks(options, type) {
40
45
  }
41
46
  class HtmlNetworkPerformancePlugin {
42
47
  constructor(options, type) {
48
+ __publicField(this, "options");
49
+ __publicField(this, "type");
43
50
  this.options = options;
44
51
  this.type = type;
45
52
  }
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var HtmlNoncePlugin_exports = {};
20
25
  __export(HtmlNoncePlugin_exports, {
21
26
  HtmlNoncePlugin: () => HtmlNoncePlugin
@@ -24,6 +29,8 @@ module.exports = __toCommonJS(HtmlNoncePlugin_exports);
24
29
  var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
25
30
  class HtmlNoncePlugin {
26
31
  constructor(options) {
32
+ __publicField(this, "name");
33
+ __publicField(this, "nonce");
27
34
  const { nonce } = options;
28
35
  this.name = "HtmlNoncePlugin";
29
36
  this.nonce = nonce;
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var HtmlTagsPlugin_exports = {};
20
25
  __export(HtmlTagsPlugin_exports, {
21
26
  FILE_ATTRS: () => FILE_ATTRS,
@@ -60,8 +65,9 @@ const FILE_ATTRS = {
60
65
  const withHash = (url, hash) => `${url}?${hash}`;
61
66
  class HtmlTagsPlugin {
62
67
  constructor(opts) {
63
- this.name = "HtmlTagsPlugin";
64
- this.meta = { plugin: this.name };
68
+ __publicField(this, "name", "HtmlTagsPlugin");
69
+ __publicField(this, "meta", { plugin: this.name });
70
+ __publicField(this, "ctx");
65
71
  this.ctx = {
66
72
  append: true,
67
73
  ...opts
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var InlineChunkHtmlPlugin_exports = {};
20
25
  __export(InlineChunkHtmlPlugin_exports, {
21
26
  InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
@@ -30,6 +35,11 @@ class InlineChunkHtmlPlugin {
30
35
  scriptTests,
31
36
  distPath
32
37
  }) {
38
+ __publicField(this, "name");
39
+ __publicField(this, "styleTests");
40
+ __publicField(this, "scriptTests");
41
+ __publicField(this, "distPath");
42
+ __publicField(this, "inlinedAssets");
33
43
  this.name = "InlineChunkHtmlPlugin";
34
44
  this.styleTests = styleTests;
35
45
  this.scriptTests = scriptTests;
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var RemoveCssSourcemapPlugin_exports = {};
20
25
  __export(RemoveCssSourcemapPlugin_exports, {
21
26
  RemoveCssSourcemapPlugin: () => RemoveCssSourcemapPlugin
@@ -23,6 +28,7 @@ __export(RemoveCssSourcemapPlugin_exports, {
23
28
  module.exports = __toCommonJS(RemoveCssSourcemapPlugin_exports);
24
29
  class RemoveCssSourcemapPlugin {
25
30
  constructor() {
31
+ __publicField(this, "name");
26
32
  this.name = "RemoveCssSourcemapPlugin";
27
33
  }
28
34
  apply(compiler) {
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var HtmlPreloadOrPrefetchPlugin_exports = {};
20
25
  __export(HtmlPreloadOrPrefetchPlugin_exports, {
21
26
  HtmlPreloadOrPrefetchPlugin: () => HtmlPreloadOrPrefetchPlugin
@@ -119,7 +124,10 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
119
124
  }
120
125
  class HtmlPreloadOrPrefetchPlugin {
121
126
  constructor(options, type, HTMLCount) {
122
- this.resourceHints = [];
127
+ __publicField(this, "options");
128
+ __publicField(this, "resourceHints", []);
129
+ __publicField(this, "type");
130
+ __publicField(this, "HTMLCount");
123
131
  this.options = {
124
132
  ...defaultOptions,
125
133
  ...typeof options === "boolean" ? {} : options
@@ -17,7 +17,7 @@
17
17
  import type { Compilation } from '@rspack/core';
18
18
  import type { Chunk } from 'webpack';
19
19
  import type { PreloadOrPreFetchOption } from '@rsbuild/shared';
20
- import { BeforeAssetTagGenerationHtmlPluginData } from './type';
20
+ import type { BeforeAssetTagGenerationHtmlPluginData } from './type';
21
21
  interface DoesChunkBelongToHtmlOptions {
22
22
  chunk: Chunk;
23
23
  compilation?: Compilation;
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Chunk, Compilation } from 'webpack';
17
+ import type { Chunk, Compilation } from 'webpack';
18
18
  import type { PreloadIncludeType } from '@rsbuild/shared';
19
19
  export type ChunkGroup = Compilation['chunkGroups'][0];
20
20
  interface ExtractChunks {
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
  var compilerDevMiddleware_exports = {};
30
35
  __export(compilerDevMiddleware_exports, {
31
36
  CompilerDevMiddleware: () => CompilerDevMiddleware
@@ -44,6 +49,11 @@ function getHMRClientPath(client) {
44
49
  }
45
50
  class CompilerDevMiddleware {
46
51
  constructor({ dev, devMiddleware, publicPaths }) {
52
+ __publicField(this, "middleware");
53
+ __publicField(this, "devOptions");
54
+ __publicField(this, "devMiddleware");
55
+ __publicField(this, "publicPaths");
56
+ __publicField(this, "socketServer");
47
57
  this.devOptions = dev;
48
58
  this.publicPaths = publicPaths;
49
59
  this.socketServer = new import_socketServer.SocketServer(dev);
@@ -1,4 +1,4 @@
1
- import { StartServerResult, type DevServerAPIs, type StartDevServerOptions, type CreateDevMiddlewareReturns } from '@rsbuild/shared';
1
+ import { type DevServerAPIs, type StartServerResult, type StartDevServerOptions, type CreateDevMiddlewareReturns } from '@rsbuild/shared';
2
2
  import type { InternalContext } from '../types';
3
3
  export declare function getServerAPIs<Options extends {
4
4
  context: InternalContext;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { Routes, DevConfig, PrintUrls, RsbuildEntry, RsbuildConfig, OutputStructure } from '@rsbuild/shared';
3
3
  export declare const formatRoutes: (entry: RsbuildEntry, prefix: string | undefined, outputStructure: OutputStructure | undefined) => Routes;
4
- export declare function printServerURLs({ urls, port, routes, protocol, printUrls, }: {
4
+ export declare function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, }: {
5
5
  urls: Array<{
6
6
  url: string;
7
7
  label: string;
@@ -34,8 +34,34 @@ const formatRoutes = (entry, prefix, outputStructure) => {
34
34
  (name === "index" && outputStructure !== "nested" ? "" : name)
35
35
  })).sort((a) => a.name === "index" ? -1 : 1);
36
36
  };
37
+ function getURLMessages(urls, routes) {
38
+ if (routes.length === 1) {
39
+ return urls.map(
40
+ ({ label, url }) => ` ${`> ${label.padEnd(10)}`}${import_shared.color.cyan(
41
+ (0, import_shared.normalizeUrl)(`${url}/${routes[0].route}`)
42
+ )}
43
+ `
44
+ ).join("");
45
+ }
46
+ let message = "";
47
+ const maxNameLength = Math.max(...routes.map((r) => r.name.length));
48
+ urls.forEach(({ label, url }, index) => {
49
+ if (index > 0) {
50
+ message += "\n";
51
+ }
52
+ message += ` ${`> ${label}`}
53
+ `;
54
+ routes.forEach((r) => {
55
+ message += ` ${import_shared.color.dim("-")} ${import_shared.color.dim(
56
+ r.name.padEnd(maxNameLength + 4)
57
+ )}${import_shared.color.cyan((0, import_shared.normalizeUrl)(`${url}/${r.route}`))}
58
+ `;
59
+ });
60
+ });
61
+ return message;
62
+ }
37
63
  function printServerURLs({
38
- urls,
64
+ urls: originalUrls,
39
65
  port,
40
66
  routes,
41
67
  protocol,
@@ -44,38 +70,30 @@ function printServerURLs({
44
70
  if (printUrls === false) {
45
71
  return;
46
72
  }
73
+ let urls = originalUrls;
47
74
  if ((0, import_shared.isFunction)(printUrls)) {
48
- printUrls({
75
+ const newUrls = printUrls({
49
76
  urls: urls.map((item) => item.url),
50
77
  port,
51
78
  protocol
52
79
  });
53
- return;
80
+ if (!newUrls) {
81
+ return;
82
+ }
83
+ if (!Array.isArray(newUrls)) {
84
+ throw new Error(
85
+ `"server.printUrls" must return an array, but got ${typeof newUrls}.`
86
+ );
87
+ }
88
+ urls = newUrls.map((url) => ({
89
+ url,
90
+ label: (0, import_shared.getUrlLabel)(url)
91
+ }));
54
92
  }
55
- let message = "";
56
- if (routes.length === 1) {
57
- message = urls.map(
58
- ({ label, url }) => ` ${`> ${label.padEnd(10)}`}${import_shared.color.cyan(
59
- (0, import_shared.normalizeUrl)(`${url}/${routes[0].route}`)
60
- )}
61
- `
62
- ).join("");
63
- } else {
64
- const maxNameLength = Math.max(...routes.map((r) => r.name.length));
65
- urls.forEach(({ label, url }, index) => {
66
- if (index > 0) {
67
- message += "\n";
68
- }
69
- message += ` ${`> ${label}`}
70
- `;
71
- routes.forEach((r) => {
72
- message += ` ${import_shared.color.dim("-")} ${import_shared.color.dim(
73
- r.name.padEnd(maxNameLength + 4)
74
- )}${import_shared.color.cyan((0, import_shared.normalizeUrl)(`${url}/${r.route}`))}
75
- `;
76
- });
77
- });
93
+ if (urls.length === 0) {
94
+ return;
78
95
  }
96
+ const message = getURLMessages(urls, routes);
79
97
  import_shared.logger.log(message);
80
98
  return message;
81
99
  }
@@ -34,6 +34,7 @@ __export(middlewares_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(middlewares_exports);
36
36
  var import_shared = require("@rsbuild/shared");
37
+ var import_url = require("url");
37
38
  var import_path = __toESM(require("path"));
38
39
  var import_fs = __toESM(require("fs"));
39
40
  const faviconFallbackMiddleware = (req, res, next) => {
@@ -62,7 +63,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
62
63
  const { url } = req;
63
64
  let pathname = url;
64
65
  try {
65
- pathname = decodeURIComponent(url);
66
+ pathname = (0, import_url.parse)(url, false, true).pathname;
66
67
  } catch (err) {
67
68
  import_shared.logger.error(
68
69
  new Error(`Invalid URL: ${import_shared.color.yellow(url)}`, { cause: err })
@@ -85,7 +86,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
85
86
  return next();
86
87
  };
87
88
  if (pathname.endsWith("/")) {
88
- const newUrl = `${url}index.html`;
89
+ const newUrl = `${pathname}index.html`;
89
90
  const filePath = import_path.default.join(distPath, pathname, "index.html");
90
91
  if (outputFileSystem.existsSync(filePath)) {
91
92
  return rewrite(newUrl);
@@ -94,7 +95,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
94
95
  // '/main' => '/main.html'
95
96
  !pathname.endsWith(".html")
96
97
  ) {
97
- const newUrl = `${url}.html`;
98
+ const newUrl = `${pathname}.html`;
98
99
  const filePath = import_path.default.join(distPath, `${pathname}.html`);
99
100
  if (outputFileSystem.existsSync(filePath)) {
100
101
  return rewrite(newUrl);
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
  var prodServer_exports = {};
30
35
  __export(prodServer_exports, {
31
36
  RsbuildProdServer: () => RsbuildProdServer,
@@ -41,7 +46,9 @@ var import_middlewares = require("./middlewares");
41
46
  var import_httpServer = require("./httpServer");
42
47
  class RsbuildProdServer {
43
48
  constructor(options) {
44
- this.middlewares = (0, import_connect.default)();
49
+ __publicField(this, "app");
50
+ __publicField(this, "options");
51
+ __publicField(this, "middlewares", (0, import_connect.default)());
45
52
  this.options = options;
46
53
  }
47
54
  // Complete the preparation of services
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
  var socketServer_exports = {};
30
35
  __export(socketServer_exports, {
31
36
  SocketServer: () => SocketServer
@@ -35,8 +40,11 @@ var import_ws = __toESM(require("../../compiled/ws"));
35
40
  var import_shared = require("@rsbuild/shared");
36
41
  class SocketServer {
37
42
  constructor(options) {
38
- this.sockets = [];
39
- this.timer = null;
43
+ __publicField(this, "wsServer");
44
+ __publicField(this, "sockets", []);
45
+ __publicField(this, "options");
46
+ __publicField(this, "stats");
47
+ __publicField(this, "timer", null);
40
48
  this.options = options;
41
49
  }
42
50
  upgrade(req, sock, head) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -61,7 +61,7 @@
61
61
  "core-js": "~3.32.2",
62
62
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
63
63
  "postcss": "8.4.31",
64
- "@rsbuild/shared": "0.3.0"
64
+ "@rsbuild/shared": "0.3.2"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/node": "16.x",