@rsbuild/core 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3101,6 +3101,122 @@ var init_esm = __esm({
3101
3101
  }
3102
3102
  });
3103
3103
 
3104
+ // src/logger.ts
3105
+ function getTime() {
3106
+ const now = /* @__PURE__ */ new Date();
3107
+ const hours = String(now.getHours()).padStart(2, "0");
3108
+ const minutes = String(now.getMinutes()).padStart(2, "0");
3109
+ const seconds = String(now.getSeconds()).padStart(2, "0");
3110
+ return `${hours}:${minutes}:${seconds}`;
3111
+ }
3112
+ var import_picocolors, import_rslog, isDebug;
3113
+ var init_logger = __esm({
3114
+ "src/logger.ts"() {
3115
+ "use strict";
3116
+ import_picocolors = __toESM(require("../compiled/picocolors/index.js"));
3117
+ import_rslog = require("../compiled/rslog/index.js");
3118
+ isDebug = () => {
3119
+ if (!process.env.DEBUG) {
3120
+ return false;
3121
+ }
3122
+ const values = process.env.DEBUG.toLocaleLowerCase().split(",");
3123
+ return ["rsbuild", "builder", "*"].some((key) => values.includes(key));
3124
+ };
3125
+ if (isDebug()) {
3126
+ import_rslog.logger.level = "verbose";
3127
+ }
3128
+ import_rslog.logger.override({
3129
+ debug: (message, ...args) => {
3130
+ if (import_rslog.logger.level !== "verbose") {
3131
+ return;
3132
+ }
3133
+ const time = import_picocolors.default.gray(`${getTime()}`);
3134
+ console.log(` ${import_picocolors.default.magenta("rsbuild")} ${time} ${message}`, ...args);
3135
+ }
3136
+ });
3137
+ }
3138
+ });
3139
+
3140
+ // src/constants.ts
3141
+ var import_node_path, ROOT_DIST_DIR, HTML_DIST_DIR, JS_DIST_DIR, CSS_DIST_DIR, SVG_DIST_DIR, FONT_DIST_DIR, WASM_DIST_DIR, IMAGE_DIST_DIR, MEDIA_DIST_DIR, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HMR_SOCKET_PATH, RSBUILD_OUTPUTS_PATH, DEFAULT_PORT, DEFAULT_DATA_URL_SIZE, DEFAULT_MOUNT_ID, DEFAULT_DEV_HOST, DEFAULT_ASSET_PREFIX, DEFAULT_WEB_BROWSERSLIST, DEFAULT_BROWSERSLIST, HTML_REGEX, JS_REGEX, SCRIPT_REGEX, CSS_REGEX, NODE_MODULES_REGEX, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, FONT_EXTENSIONS, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, AUDIO_EXTENSIONS;
3142
+ var init_constants = __esm({
3143
+ "src/constants.ts"() {
3144
+ "use strict";
3145
+ import_node_path = require("path");
3146
+ ROOT_DIST_DIR = "dist";
3147
+ HTML_DIST_DIR = "./";
3148
+ JS_DIST_DIR = "static/js";
3149
+ CSS_DIST_DIR = "static/css";
3150
+ SVG_DIST_DIR = "static/svg";
3151
+ FONT_DIST_DIR = "static/font";
3152
+ WASM_DIST_DIR = "static/wasm";
3153
+ IMAGE_DIST_DIR = "static/image";
3154
+ MEDIA_DIST_DIR = "static/media";
3155
+ LOADER_PATH = (0, import_node_path.join)(__dirname);
3156
+ STATIC_PATH = (0, import_node_path.join)(__dirname, "../static");
3157
+ COMPILED_PATH = (0, import_node_path.join)(__dirname, "../compiled");
3158
+ TS_CONFIG_FILE = "tsconfig.json";
3159
+ HMR_SOCKET_PATH = "/rsbuild-hmr";
3160
+ RSBUILD_OUTPUTS_PATH = ".rsbuild";
3161
+ DEFAULT_PORT = 3e3;
3162
+ DEFAULT_DATA_URL_SIZE = 4096;
3163
+ DEFAULT_MOUNT_ID = "root";
3164
+ DEFAULT_DEV_HOST = "0.0.0.0";
3165
+ DEFAULT_ASSET_PREFIX = "/";
3166
+ DEFAULT_WEB_BROWSERSLIST = [
3167
+ "chrome >= 87",
3168
+ "edge >= 88",
3169
+ "firefox >= 78",
3170
+ "safari >= 14"
3171
+ ];
3172
+ DEFAULT_BROWSERSLIST = {
3173
+ web: DEFAULT_WEB_BROWSERSLIST,
3174
+ "web-worker": DEFAULT_WEB_BROWSERSLIST,
3175
+ node: ["node >= 16"]
3176
+ };
3177
+ HTML_REGEX = /\.html$/;
3178
+ JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
3179
+ SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
3180
+ CSS_REGEX = /\.css$/;
3181
+ NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
3182
+ PLUGIN_SWC_NAME = "rsbuild:swc";
3183
+ PLUGIN_CSS_NAME = "rsbuild:css";
3184
+ FONT_EXTENSIONS = [
3185
+ "woff",
3186
+ "woff2",
3187
+ "eot",
3188
+ "ttf",
3189
+ "otf",
3190
+ "ttc"
3191
+ ];
3192
+ IMAGE_EXTENSIONS = [
3193
+ "png",
3194
+ "jpg",
3195
+ "jpeg",
3196
+ "pjpeg",
3197
+ "pjp",
3198
+ "gif",
3199
+ "bmp",
3200
+ "webp",
3201
+ "ico",
3202
+ "apng",
3203
+ "avif",
3204
+ "tif",
3205
+ "tiff",
3206
+ "jfif"
3207
+ ];
3208
+ VIDEO_EXTENSIONS = ["mp4", "webm", "ogg", "mov"];
3209
+ AUDIO_EXTENSIONS = [
3210
+ "mp3",
3211
+ "wav",
3212
+ "flac",
3213
+ "aac",
3214
+ "m4a",
3215
+ "opus"
3216
+ ];
3217
+ }
3218
+ });
3219
+
3104
3220
  // ../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js
3105
3221
  var require_cjs = __commonJS({
3106
3222
  "../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"(exports, module2) {
@@ -3204,122 +3320,6 @@ var require_cjs = __commonJS({
3204
3320
  }
3205
3321
  });
3206
3322
 
3207
- // src/constants.ts
3208
- var import_node_path, ROOT_DIST_DIR, HTML_DIST_DIR, JS_DIST_DIR, CSS_DIST_DIR, SVG_DIST_DIR, FONT_DIST_DIR, WASM_DIST_DIR, IMAGE_DIST_DIR, MEDIA_DIST_DIR, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HMR_SOCKET_PATH, RSBUILD_OUTPUTS_PATH, DEFAULT_PORT, DEFAULT_DATA_URL_SIZE, DEFAULT_MOUNT_ID, DEFAULT_DEV_HOST, DEFAULT_ASSET_PREFIX, DEFAULT_WEB_BROWSERSLIST, DEFAULT_BROWSERSLIST, HTML_REGEX, JS_REGEX, SCRIPT_REGEX, CSS_REGEX, NODE_MODULES_REGEX, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, FONT_EXTENSIONS, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, AUDIO_EXTENSIONS;
3209
- var init_constants = __esm({
3210
- "src/constants.ts"() {
3211
- "use strict";
3212
- import_node_path = require("path");
3213
- ROOT_DIST_DIR = "dist";
3214
- HTML_DIST_DIR = "./";
3215
- JS_DIST_DIR = "static/js";
3216
- CSS_DIST_DIR = "static/css";
3217
- SVG_DIST_DIR = "static/svg";
3218
- FONT_DIST_DIR = "static/font";
3219
- WASM_DIST_DIR = "static/wasm";
3220
- IMAGE_DIST_DIR = "static/image";
3221
- MEDIA_DIST_DIR = "static/media";
3222
- LOADER_PATH = (0, import_node_path.join)(__dirname);
3223
- STATIC_PATH = (0, import_node_path.join)(__dirname, "../static");
3224
- COMPILED_PATH = (0, import_node_path.join)(__dirname, "../compiled");
3225
- TS_CONFIG_FILE = "tsconfig.json";
3226
- HMR_SOCKET_PATH = "/rsbuild-hmr";
3227
- RSBUILD_OUTPUTS_PATH = ".rsbuild";
3228
- DEFAULT_PORT = 3e3;
3229
- DEFAULT_DATA_URL_SIZE = 4096;
3230
- DEFAULT_MOUNT_ID = "root";
3231
- DEFAULT_DEV_HOST = "0.0.0.0";
3232
- DEFAULT_ASSET_PREFIX = "/";
3233
- DEFAULT_WEB_BROWSERSLIST = [
3234
- "chrome >= 87",
3235
- "edge >= 88",
3236
- "firefox >= 78",
3237
- "safari >= 14"
3238
- ];
3239
- DEFAULT_BROWSERSLIST = {
3240
- web: DEFAULT_WEB_BROWSERSLIST,
3241
- "web-worker": DEFAULT_WEB_BROWSERSLIST,
3242
- node: ["node >= 16"]
3243
- };
3244
- HTML_REGEX = /\.html$/;
3245
- JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
3246
- SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
3247
- CSS_REGEX = /\.css$/;
3248
- NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
3249
- PLUGIN_SWC_NAME = "rsbuild:swc";
3250
- PLUGIN_CSS_NAME = "rsbuild:css";
3251
- FONT_EXTENSIONS = [
3252
- "woff",
3253
- "woff2",
3254
- "eot",
3255
- "ttf",
3256
- "otf",
3257
- "ttc"
3258
- ];
3259
- IMAGE_EXTENSIONS = [
3260
- "png",
3261
- "jpg",
3262
- "jpeg",
3263
- "pjpeg",
3264
- "pjp",
3265
- "gif",
3266
- "bmp",
3267
- "webp",
3268
- "ico",
3269
- "apng",
3270
- "avif",
3271
- "tif",
3272
- "tiff",
3273
- "jfif"
3274
- ];
3275
- VIDEO_EXTENSIONS = ["mp4", "webm", "ogg", "mov"];
3276
- AUDIO_EXTENSIONS = [
3277
- "mp3",
3278
- "wav",
3279
- "flac",
3280
- "aac",
3281
- "m4a",
3282
- "opus"
3283
- ];
3284
- }
3285
- });
3286
-
3287
- // src/logger.ts
3288
- function getTime() {
3289
- const now = /* @__PURE__ */ new Date();
3290
- const hours = String(now.getHours()).padStart(2, "0");
3291
- const minutes = String(now.getMinutes()).padStart(2, "0");
3292
- const seconds = String(now.getSeconds()).padStart(2, "0");
3293
- return `${hours}:${minutes}:${seconds}`;
3294
- }
3295
- var import_picocolors, import_rslog, isDebug;
3296
- var init_logger = __esm({
3297
- "src/logger.ts"() {
3298
- "use strict";
3299
- import_picocolors = __toESM(require("../compiled/picocolors/index.js"));
3300
- import_rslog = require("../compiled/rslog/index.js");
3301
- isDebug = () => {
3302
- if (!process.env.DEBUG) {
3303
- return false;
3304
- }
3305
- const values = process.env.DEBUG.toLocaleLowerCase().split(",");
3306
- return ["rsbuild", "builder", "*"].some((key) => values.includes(key));
3307
- };
3308
- if (isDebug()) {
3309
- import_rslog.logger.level = "verbose";
3310
- }
3311
- import_rslog.logger.override({
3312
- debug: (message, ...args) => {
3313
- if (import_rslog.logger.level !== "verbose") {
3314
- return;
3315
- }
3316
- const time = import_picocolors.default.gray(`${getTime()}`);
3317
- console.log(` ${import_picocolors.default.magenta("rsbuild")} ${time} ${message}`, ...args);
3318
- }
3319
- });
3320
- }
3321
- });
3322
-
3323
3323
  // src/helpers/fs.ts
3324
3324
  function isEmptyDir(path21) {
3325
3325
  const files = import_node_fs.default.readdirSync(path21);
@@ -3980,12 +3980,21 @@ var init_restart = __esm({
3980
3980
  }
3981
3981
  };
3982
3982
  restartDevServer = async ({
3983
- filePath
3984
- }) => {
3985
- clearConsole();
3986
- const filename = import_node_path5.default.basename(filePath);
3987
- import_rslog.logger.info(`Restart because ${import_picocolors4.default.yellow(filename)} is changed.
3988
- `);
3983
+ filePath,
3984
+ clear = true
3985
+ } = {}) => {
3986
+ if (clear) {
3987
+ clearConsole();
3988
+ }
3989
+ if (filePath) {
3990
+ const filename = import_node_path5.default.basename(filePath);
3991
+ import_rslog.logger.info(
3992
+ `Restart server because ${import_picocolors4.default.yellow(filename)} is changed.
3993
+ `
3994
+ );
3995
+ } else {
3996
+ import_rslog.logger.info("Restarting server...\n");
3997
+ }
3989
3998
  for (const cleaner of cleaners) {
3990
3999
  await cleaner();
3991
4000
  cleaners = [];
@@ -4022,7 +4031,7 @@ function getDefaultEntry(root) {
4022
4031
  function defineConfig(config) {
4023
4032
  return config;
4024
4033
  }
4025
- async function watchFiles(files, watchOptions) {
4034
+ async function watchFilesForRestart(files, watchOptions) {
4026
4035
  if (!files.length) {
4027
4036
  return;
4028
4037
  }
@@ -4197,6 +4206,7 @@ var init_config = __esm({
4197
4206
  // Temporary placeholder, default: `${server.base}`
4198
4207
  assetPrefix: DEFAULT_ASSET_PREFIX,
4199
4208
  writeToDisk: false,
4209
+ cliShortcuts: false,
4200
4210
  client: {
4201
4211
  path: HMR_SOCKET_PATH,
4202
4212
  port: "",
@@ -5995,7 +6005,7 @@ async function createContext(options, userConfig, bundlerType) {
5995
6005
  const rsbuildConfig = await withDefaultConfig(rootPath, userConfig);
5996
6006
  const cachePath = (0, import_node_path10.join)(rootPath, "node_modules", ".cache");
5997
6007
  return {
5998
- version: "1.0.10",
6008
+ version: "1.0.11",
5999
6009
  rootPath,
6000
6010
  distPath: "",
6001
6011
  cachePath,
@@ -6873,6 +6883,96 @@ var init_createCompiler = __esm({
6873
6883
  }
6874
6884
  });
6875
6885
 
6886
+ // src/server/cliShortcuts.ts
6887
+ function setupCliShortcuts({
6888
+ openPage,
6889
+ closeServer,
6890
+ printUrls,
6891
+ restartServer,
6892
+ customShortcuts
6893
+ }) {
6894
+ let shortcuts = [
6895
+ {
6896
+ key: "c",
6897
+ description: `${import_picocolors9.default.bold("c + enter")} ${import_picocolors9.default.dim("clear console")}`,
6898
+ action: () => {
6899
+ console.clear();
6900
+ }
6901
+ },
6902
+ {
6903
+ key: "o",
6904
+ description: `${import_picocolors9.default.bold("o + enter")} ${import_picocolors9.default.dim("open in browser")}`,
6905
+ action: openPage
6906
+ },
6907
+ {
6908
+ key: "q",
6909
+ description: `${import_picocolors9.default.bold("q + enter")} ${import_picocolors9.default.dim("quit process")}`,
6910
+ action: async () => {
6911
+ try {
6912
+ await closeServer();
6913
+ } finally {
6914
+ process.exit(0);
6915
+ }
6916
+ }
6917
+ },
6918
+ restartServer ? {
6919
+ key: "r",
6920
+ description: `${import_picocolors9.default.bold("r + enter")} ${import_picocolors9.default.dim("restart server")}`,
6921
+ action: restartServer
6922
+ } : null,
6923
+ {
6924
+ key: "u",
6925
+ description: `${import_picocolors9.default.bold("u + enter")} ${import_picocolors9.default.dim("show urls")}`,
6926
+ action: printUrls
6927
+ }
6928
+ ].filter(Boolean);
6929
+ if (customShortcuts) {
6930
+ shortcuts = customShortcuts(shortcuts);
6931
+ if (!Array.isArray(shortcuts)) {
6932
+ throw new Error("`dev.cliShortcuts` must return an array of shortcuts.");
6933
+ }
6934
+ }
6935
+ import_rslog.logger.log(
6936
+ ` ➜ ${import_picocolors9.default.dim("press")} ${import_picocolors9.default.bold("h + enter")} ${import_picocolors9.default.dim("to show shortcuts")}
6937
+ `
6938
+ );
6939
+ const rl = import_node_readline.default.createInterface({
6940
+ input: process.stdin
6941
+ });
6942
+ rl.on("line", (input) => {
6943
+ if (input === "h") {
6944
+ let message = `
6945
+ ${import_picocolors9.default.bold(import_picocolors9.default.blue("Shortcuts:"))}
6946
+ `;
6947
+ for (const shortcut of shortcuts) {
6948
+ message += ` ${shortcut.description}
6949
+ `;
6950
+ }
6951
+ import_rslog.logger.log(message);
6952
+ }
6953
+ for (const shortcut of shortcuts) {
6954
+ if (input === shortcut.key) {
6955
+ shortcut.action();
6956
+ return;
6957
+ }
6958
+ }
6959
+ });
6960
+ onBeforeRestartServer(() => {
6961
+ rl.close();
6962
+ });
6963
+ }
6964
+ var import_node_readline, import_picocolors9, isCliShortcutsEnabled;
6965
+ var init_cliShortcuts = __esm({
6966
+ "src/server/cliShortcuts.ts"() {
6967
+ "use strict";
6968
+ import_node_readline = __toESM(require("readline"));
6969
+ import_picocolors9 = __toESM(require("../compiled/picocolors/index.js"));
6970
+ init_logger();
6971
+ init_restart();
6972
+ isCliShortcutsEnabled = (devConfig) => devConfig.cliShortcuts && process.stdin.isTTY && !process.env.CI;
6973
+ }
6974
+ });
6975
+
6876
6976
  // src/server/runner/asModule.ts
6877
6977
  var import_node_vm, SYNTHETIC_MODULES_STORE, asModule;
6878
6978
  var init_asModule = __esm({
@@ -7295,12 +7395,12 @@ var init_environment = __esm({
7295
7395
  // src/server/helper.ts
7296
7396
  function getURLMessages(urls, routes) {
7297
7397
  if (routes.length === 1) {
7298
- return urls.map(
7299
- ({ label, url: url2 }) => ` ${`➜ ${label.padEnd(10)}`}${import_picocolors9.default.cyan(
7300
- normalizeUrl(`${url2}${routes[0].pathname}`)
7301
- )}
7302
- `
7303
- ).join("");
7398
+ return urls.map(({ label, url: url2 }) => {
7399
+ const pathname = normalizeUrl(`${url2}${routes[0].pathname}`);
7400
+ const prefix = `➜ ${import_picocolors10.default.dim(label.padEnd(10))}`;
7401
+ return ` ${prefix}${import_picocolors10.default.cyan(pathname)}
7402
+ `;
7403
+ }).join("");
7304
7404
  }
7305
7405
  let message = "";
7306
7406
  const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
@@ -7311,9 +7411,9 @@ function getURLMessages(urls, routes) {
7311
7411
  message += ` ${`➜ ${label}`}
7312
7412
  `;
7313
7413
  for (const r of routes) {
7314
- message += ` ${import_picocolors9.default.dim("-")} ${import_picocolors9.default.dim(
7414
+ message += ` ${import_picocolors10.default.dim("-")} ${import_picocolors10.default.dim(
7315
7415
  r.entryName.padEnd(maxNameLength + 4)
7316
- )}${import_picocolors9.default.cyan(normalizeUrl(`${url2}${r.pathname}`))}
7416
+ )}${import_picocolors10.default.cyan(normalizeUrl(`${url2}${r.pathname}`))}
7317
7417
  `;
7318
7418
  }
7319
7419
  });
@@ -7324,7 +7424,8 @@ function printServerURLs({
7324
7424
  port,
7325
7425
  routes,
7326
7426
  protocol,
7327
- printUrls
7427
+ printUrls,
7428
+ trailingLineBreak = true
7328
7429
  }) {
7329
7430
  if (printUrls === false) {
7330
7431
  return null;
@@ -7353,7 +7454,10 @@ function printServerURLs({
7353
7454
  if (urls.length === 0 || routes.length === 0) {
7354
7455
  return null;
7355
7456
  }
7356
- const message = getURLMessages(urls, routes);
7457
+ let message = getURLMessages(urls, routes);
7458
+ if (trailingLineBreak === false && message.endsWith("\n")) {
7459
+ message = message.slice(0, -1);
7460
+ }
7357
7461
  import_rslog.logger.log(message);
7358
7462
  return message;
7359
7463
  }
@@ -7382,14 +7486,14 @@ function getServerTerminator(server) {
7382
7486
  }
7383
7487
  });
7384
7488
  }
7385
- var import_node_net, import_node_os, import_node_path16, import_picocolors9, normalizeUrl, formatPrefix, joinUrlSegments, stripBase, getRoutes, formatRoutes, getPort, getServerConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls, COMPILATION_ID_REGEX, getCompilationId;
7489
+ var import_node_net, import_node_os, import_node_path16, import_picocolors10, normalizeUrl, formatPrefix, joinUrlSegments, stripBase, getRoutes, formatRoutes, getPort, getServerConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls, COMPILATION_ID_REGEX, getCompilationId;
7386
7490
  var init_helper = __esm({
7387
7491
  "src/server/helper.ts"() {
7388
7492
  "use strict";
7389
7493
  import_node_net = __toESM(require("net"));
7390
7494
  import_node_os = __toESM(require("os"));
7391
7495
  import_node_path16 = require("path");
7392
- import_picocolors9 = __toESM(require("../compiled/picocolors/index.js"));
7496
+ import_picocolors10 = __toESM(require("../compiled/picocolors/index.js"));
7393
7497
  init_constants();
7394
7498
  init_helpers();
7395
7499
  init_logger();
@@ -7500,7 +7604,7 @@ var init_helper = __esm({
7500
7604
  strictPort: config.server.strictPort || false
7501
7605
  });
7502
7606
  const https = Boolean(config.server.https) || false;
7503
- const portTip = port !== originalPort ? `Port ${originalPort} is in use, ${import_picocolors9.default.yellow(`using port ${port}.`)}` : void 0;
7607
+ const portTip = port !== originalPort ? `Port ${originalPort} is in use, ${import_picocolors10.default.yellow(`using port ${port}.`)}` : void 0;
7504
7608
  return {
7505
7609
  port,
7506
7610
  host,
@@ -7599,12 +7703,12 @@ var init_helper = __esm({
7599
7703
  });
7600
7704
 
7601
7705
  // src/server/middlewares.ts
7602
- var import_node_path17, import_picocolors10, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, isFileExists2, maybeHTMLRequest, postfixRE, getUrlPathname, getHtmlCompletionMiddleware, getBaseMiddleware, getHtmlFallbackMiddleware;
7706
+ var import_node_path17, import_picocolors11, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, isFileExists2, maybeHTMLRequest, postfixRE, getUrlPathname, getHtmlCompletionMiddleware, getBaseMiddleware, getHtmlFallbackMiddleware;
7603
7707
  var init_middlewares = __esm({
7604
7708
  "src/server/middlewares.ts"() {
7605
7709
  "use strict";
7606
7710
  import_node_path17 = __toESM(require("path"));
7607
- import_picocolors10 = __toESM(require("../compiled/picocolors/index.js"));
7711
+ import_picocolors11 = __toESM(require("../compiled/picocolors/index.js"));
7608
7712
  init_helpers();
7609
7713
  init_logger();
7610
7714
  init_helper();
@@ -7618,16 +7722,16 @@ var init_middlewares = __esm({
7618
7722
  };
7619
7723
  getStatusCodeColor = (status) => {
7620
7724
  if (status >= 500) {
7621
- return import_picocolors10.default.red;
7725
+ return import_picocolors11.default.red;
7622
7726
  }
7623
7727
  if (status >= 400) {
7624
- return import_picocolors10.default.yellow;
7728
+ return import_picocolors11.default.yellow;
7625
7729
  }
7626
7730
  if (status >= 300) {
7627
- return import_picocolors10.default.cyan;
7731
+ return import_picocolors11.default.cyan;
7628
7732
  }
7629
7733
  if (status >= 200) {
7630
- return import_picocolors10.default.green;
7734
+ return import_picocolors11.default.green;
7631
7735
  }
7632
7736
  return (res) => res;
7633
7737
  };
@@ -7643,7 +7747,7 @@ var init_middlewares = __esm({
7643
7747
  const endAt = process.hrtime();
7644
7748
  const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
7645
7749
  import_rslog.logger.debug(
7646
- `${statusColor(status)} ${method} ${import_picocolors10.default.gray(url2)} ${import_picocolors10.default.gray(
7750
+ `${statusColor(status)} ${method} ${import_picocolors11.default.gray(url2)} ${import_picocolors11.default.gray(
7647
7751
  `${totalTime.toFixed(3)} ms`
7648
7752
  )}`
7649
7753
  );
@@ -7751,8 +7855,8 @@ var init_middlewares = __esm({
7751
7855
  const newUrl = "/index.html";
7752
7856
  if (import_rslog.logger.level === "verbose") {
7753
7857
  import_rslog.logger.debug(
7754
- `${req.method} ${import_picocolors10.default.gray(
7755
- `${req.url} ${import_picocolors10.default.yellow("fallback")} to ${newUrl}`
7858
+ `${req.method} ${import_picocolors11.default.gray(
7859
+ `${req.url} ${import_picocolors11.default.yellow("fallback")} to ${newUrl}`
7756
7860
  )}`
7757
7861
  );
7758
7862
  }
@@ -8284,7 +8388,7 @@ async function setupWatchFiles(options) {
8284
8388
  if (!hmr && !liveReload || !compileMiddlewareAPI) {
8285
8389
  return;
8286
8390
  }
8287
- const devFilesWatcher = await watchDevFiles(dev, compileMiddlewareAPI);
8391
+ const closeDevFilesWatcher = await watchDevFiles(dev, compileMiddlewareAPI);
8288
8392
  const serverFilesWatcher = await watchServerFiles(
8289
8393
  server,
8290
8394
  compileMiddlewareAPI
@@ -8292,23 +8396,30 @@ async function setupWatchFiles(options) {
8292
8396
  return {
8293
8397
  async close() {
8294
8398
  await Promise.all([
8295
- devFilesWatcher?.close(),
8399
+ closeDevFilesWatcher?.(),
8296
8400
  serverFilesWatcher?.close()
8297
8401
  ]);
8298
8402
  }
8299
8403
  };
8300
8404
  }
8301
8405
  async function watchDevFiles(devConfig, compileMiddlewareAPI) {
8302
- const { watchFiles: watchFiles2 } = devConfig;
8303
- if (!watchFiles2) {
8406
+ const { watchFiles } = devConfig;
8407
+ if (!watchFiles) {
8304
8408
  return;
8305
8409
  }
8306
- const watchOptions = prepareWatchOptions(
8307
- watchFiles2.paths,
8308
- watchFiles2.options,
8309
- watchFiles2.type
8310
- );
8311
- return startWatchFiles(watchOptions, compileMiddlewareAPI);
8410
+ const watchers = [];
8411
+ for (const { paths, options, type } of castArray(watchFiles)) {
8412
+ const watchOptions = prepareWatchOptions(paths, options, type);
8413
+ const watcher = await startWatchFiles(watchOptions, compileMiddlewareAPI);
8414
+ if (watcher) {
8415
+ watchers.push(watcher);
8416
+ }
8417
+ }
8418
+ return async () => {
8419
+ for (const watcher of watchers) {
8420
+ await watcher.close();
8421
+ }
8422
+ };
8312
8423
  }
8313
8424
  function watchServerFiles(serverConfig, compileMiddlewareAPI) {
8314
8425
  const publicDirs = normalizePublicDirs(serverConfig.publicDir);
@@ -8344,6 +8455,7 @@ var init_watchFiles = __esm({
8344
8455
  "src/server/watchFiles.ts"() {
8345
8456
  "use strict";
8346
8457
  init_config();
8458
+ init_helpers();
8347
8459
  }
8348
8460
  });
8349
8461
 
@@ -8825,22 +8937,47 @@ async function createDevServer(options, createCompiler2, config, {
8825
8937
  await options.context.hooks.onBeforeStartDevServer.call({
8826
8938
  environments: options.context.environments
8827
8939
  });
8828
- const printUrls = () => {
8829
- printServerURLs({
8830
- urls,
8940
+ const cliShortcutsEnabled = isCliShortcutsEnabled(devConfig);
8941
+ const printUrls = () => printServerURLs({
8942
+ urls,
8943
+ port,
8944
+ routes,
8945
+ protocol,
8946
+ printUrls: config.server.printUrls,
8947
+ trailingLineBreak: !cliShortcutsEnabled
8948
+ });
8949
+ const openPage = async () => {
8950
+ return open({
8951
+ https,
8831
8952
  port,
8832
8953
  routes,
8833
- protocol,
8834
- printUrls: config.server.printUrls
8954
+ config,
8955
+ clearCache: true
8835
8956
  });
8957
+ };
8958
+ const closeServer = async () => {
8959
+ await options.context.hooks.onCloseDevServer.call();
8960
+ await Promise.all([devMiddlewares.close(), fileWatcher?.close()]);
8961
+ };
8962
+ const beforeCreateCompiler = () => {
8963
+ printUrls();
8964
+ if (cliShortcutsEnabled) {
8965
+ setupCliShortcuts({
8966
+ openPage,
8967
+ closeServer,
8968
+ printUrls,
8969
+ restartServer: () => restartDevServer({ clear: false }),
8970
+ customShortcuts: typeof devConfig.cliShortcuts === "boolean" ? void 0 : devConfig.cliShortcuts.custom
8971
+ });
8972
+ }
8836
8973
  if (!getPortSilently && portTip) {
8837
8974
  import_rslog.logger.info(portTip);
8838
8975
  }
8839
8976
  };
8840
8977
  if (runCompile) {
8841
- options.context.hooks.onBeforeCreateCompiler.tap(printUrls);
8978
+ options.context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler);
8842
8979
  } else {
8843
- printUrls();
8980
+ beforeCreateCompiler();
8844
8981
  }
8845
8982
  const compileMiddlewareAPI = runCompile ? await startCompile() : void 0;
8846
8983
  const fileWatcher = await setupWatchFiles({
@@ -8953,20 +9090,9 @@ async function createDevServer(options, createCompiler2, config, {
8953
9090
  connectWebSocket: ({ server }) => {
8954
9091
  server.on("upgrade", devMiddlewares.onUpgrade);
8955
9092
  },
8956
- close: async () => {
8957
- await options.context.hooks.onCloseDevServer.call();
8958
- await Promise.all([devMiddlewares.close(), fileWatcher?.close()]);
8959
- },
9093
+ close: closeServer,
8960
9094
  printUrls,
8961
- open: async () => {
8962
- return open({
8963
- https,
8964
- port,
8965
- routes,
8966
- config,
8967
- clearCache: true
8968
- });
8969
- }
9095
+ open: openPage
8970
9096
  };
8971
9097
  import_rslog.logger.debug("create dev server done");
8972
9098
  return devServerAPI;
@@ -8979,6 +9105,7 @@ var init_devServer = __esm({
8979
9105
  init_constants();
8980
9106
  init_helpers();
8981
9107
  init_logger();
9108
+ init_cliShortcuts();
8982
9109
  init_environment();
8983
9110
  init_getDevMiddlewares();
8984
9111
  init_helper();
@@ -9204,11 +9331,11 @@ var entry_exports = {};
9204
9331
  __export(entry_exports, {
9205
9332
  pluginEntry: () => pluginEntry
9206
9333
  });
9207
- var import_picocolors11, pluginEntry;
9334
+ var import_picocolors12, pluginEntry;
9208
9335
  var init_entry = __esm({
9209
9336
  "src/plugins/entry.ts"() {
9210
9337
  "use strict";
9211
- import_picocolors11 = __toESM(require("../compiled/picocolors/index.js"));
9338
+ import_picocolors12 = __toESM(require("../compiled/picocolors/index.js"));
9212
9339
  init_helpers();
9213
9340
  pluginEntry = () => ({
9214
9341
  name: "rsbuild:entry",
@@ -9237,9 +9364,9 @@ var init_entry = __esm({
9237
9364
  api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
9238
9365
  if (bundlerConfigs.every((config) => !config.entry)) {
9239
9366
  throw new Error(
9240
- `Could not find any entry module, please make sure that ${import_picocolors11.default.cyan(
9367
+ `Could not find any entry module, please make sure that ${import_picocolors12.default.cyan(
9241
9368
  "src/index.(ts|js|tsx|jsx|mjs|cjs)"
9242
- )} exists, or customize entry through the ${import_picocolors11.default.cyan(
9369
+ )} exists, or customize entry through the ${import_picocolors12.default.cyan(
9243
9370
  "source.entry"
9244
9371
  )} configuration.`
9245
9372
  );
@@ -9816,7 +9943,7 @@ function getHeader(longestFileLength, longestLabelLength, options) {
9816
9943
  }
9817
9944
  return `${prev + curLabel} `;
9818
9945
  }, " ");
9819
- return import_picocolors12.default.bold(import_picocolors12.default.blue(headerRow));
9946
+ return import_picocolors13.default.bold(import_picocolors13.default.blue(headerRow));
9820
9947
  }
9821
9948
  async function printFileSizes(options, stats, rootPath) {
9822
9949
  const logs = [];
@@ -9889,7 +10016,7 @@ async function printFileSizes(options, stats, rootPath) {
9889
10016
  const rightPadding = " ".repeat(longestLabelLength - sizeLength);
9890
10017
  sizeLabel += rightPadding;
9891
10018
  }
9892
- let fileNameLabel = import_picocolors12.default.dim(asset.folder + import_node_path23.default.sep) + coloringAssetName(asset.name);
10019
+ let fileNameLabel = import_picocolors13.default.dim(asset.folder + import_node_path23.default.sep) + coloringAssetName(asset.name);
9893
10020
  if (fileNameLength < longestFileLength) {
9894
10021
  const rightPadding = " ".repeat(longestFileLength - fileNameLength);
9895
10022
  fileNameLabel += rightPadding;
@@ -9902,15 +10029,15 @@ async function printFileSizes(options, stats, rootPath) {
9902
10029
  }
9903
10030
  }
9904
10031
  if (options.total !== false) {
9905
- const totalSizeLabel = `${import_picocolors12.default.bold(
9906
- import_picocolors12.default.blue("Total size:")
10032
+ const totalSizeLabel = `${import_picocolors13.default.bold(
10033
+ import_picocolors13.default.blue("Total size:")
9907
10034
  )} ${calcFileSize(totalSize)}`;
9908
10035
  let log = `
9909
10036
  ${totalSizeLabel}
9910
10037
  `;
9911
10038
  if (options.compressed) {
9912
- const gzippedSizeLabel = `${import_picocolors12.default.bold(
9913
- import_picocolors12.default.blue("Gzipped size:")
10039
+ const gzippedSizeLabel = `${import_picocolors13.default.bold(
10040
+ import_picocolors13.default.blue("Gzipped size:")
9914
10041
  )} ${calcFileSize(totalGzipSize)}`;
9915
10042
  log += ` ${gzippedSizeLabel}
9916
10043
  `;
@@ -9919,7 +10046,7 @@ async function printFileSizes(options, stats, rootPath) {
9919
10046
  }
9920
10047
  return logs;
9921
10048
  }
9922
- var import_node_fs7, import_node_path23, import_node_util2, import_node_zlib2, import_picocolors12, gzip, filterAsset, getAssetColor, calcFileSize, coloringAssetName, pluginFileSize;
10049
+ var import_node_fs7, import_node_path23, import_node_util2, import_node_zlib2, import_picocolors13, gzip, filterAsset, getAssetColor, calcFileSize, coloringAssetName, pluginFileSize;
9923
10050
  var init_fileSize = __esm({
9924
10051
  "src/plugins/fileSize.ts"() {
9925
10052
  "use strict";
@@ -9927,19 +10054,19 @@ var init_fileSize = __esm({
9927
10054
  import_node_path23 = __toESM(require("path"));
9928
10055
  import_node_util2 = require("util");
9929
10056
  import_node_zlib2 = __toESM(require("zlib"));
9930
- import_picocolors12 = __toESM(require("../compiled/picocolors/index.js"));
10057
+ import_picocolors13 = __toESM(require("../compiled/picocolors/index.js"));
9931
10058
  init_constants();
9932
10059
  init_logger();
9933
10060
  gzip = (0, import_node_util2.promisify)(import_node_zlib2.default.gzip);
9934
10061
  filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
9935
10062
  getAssetColor = (size) => {
9936
10063
  if (size > 300 * 1e3) {
9937
- return import_picocolors12.default.red;
10064
+ return import_picocolors13.default.red;
9938
10065
  }
9939
10066
  if (size > 100 * 1e3) {
9940
- return import_picocolors12.default.yellow;
10067
+ return import_picocolors13.default.yellow;
9941
10068
  }
9942
- return import_picocolors12.default.green;
10069
+ return import_picocolors13.default.green;
9943
10070
  };
9944
10071
  calcFileSize = (len) => {
9945
10072
  const val = len / 1e3;
@@ -9947,15 +10074,15 @@ var init_fileSize = __esm({
9947
10074
  };
9948
10075
  coloringAssetName = (assetName) => {
9949
10076
  if (JS_REGEX.test(assetName)) {
9950
- return import_picocolors12.default.cyan(assetName);
10077
+ return import_picocolors13.default.cyan(assetName);
9951
10078
  }
9952
10079
  if (CSS_REGEX.test(assetName)) {
9953
- return import_picocolors12.default.yellow(assetName);
10080
+ return import_picocolors13.default.yellow(assetName);
9954
10081
  }
9955
10082
  if (HTML_REGEX.test(assetName)) {
9956
- return import_picocolors12.default.green(assetName);
10083
+ return import_picocolors13.default.green(assetName);
9957
10084
  }
9958
- return import_picocolors12.default.magenta(assetName);
10085
+ return import_picocolors13.default.magenta(assetName);
9959
10086
  };
9960
10087
  pluginFileSize = () => ({
9961
10088
  name: "rsbuild:file-size",
@@ -9985,7 +10112,7 @@ var init_fileSize = __esm({
9985
10112
  multiStats[index],
9986
10113
  api.context.rootPath
9987
10114
  );
9988
- const name = import_picocolors12.default.green(environment.name);
10115
+ const name = import_picocolors13.default.green(environment.name);
9989
10116
  import_rslog.logger.info(`Production file sizes for ${name}:
9990
10117
  `);
9991
10118
  for (const log of statsLog) {
@@ -10008,12 +10135,12 @@ __export(cleanOutput_exports, {
10008
10135
  dedupeCleanPaths: () => dedupeCleanPaths,
10009
10136
  pluginCleanOutput: () => pluginCleanOutput
10010
10137
  });
10011
- var import_node_path24, import_picocolors13, addTrailingSep, isStrictSubdir, dedupeCleanPaths, pluginCleanOutput;
10138
+ var import_node_path24, import_picocolors14, addTrailingSep, isStrictSubdir, dedupeCleanPaths, pluginCleanOutput;
10012
10139
  var init_cleanOutput = __esm({
10013
10140
  "src/plugins/cleanOutput.ts"() {
10014
10141
  "use strict";
10015
10142
  import_node_path24 = require("path");
10016
- import_picocolors13 = __toESM(require("../compiled/picocolors/index.js"));
10143
+ import_picocolors14 = __toESM(require("../compiled/picocolors/index.js"));
10017
10144
  init_constants();
10018
10145
  init_helpers();
10019
10146
  init_logger();
@@ -10056,10 +10183,10 @@ var init_cleanOutput = __esm({
10056
10183
  "The dist path is not a subdir of root path, Rsbuild will not empty it."
10057
10184
  );
10058
10185
  import_rslog.logger.warn(
10059
- `Please set ${import_picocolors13.default.yellow("`output.cleanDistPath`")} config manually.`
10186
+ `Please set ${import_picocolors14.default.yellow("`output.cleanDistPath`")} config manually.`
10060
10187
  );
10061
- import_rslog.logger.warn(`Current root path: ${import_picocolors13.default.dim(rootPath)}`);
10062
- import_rslog.logger.warn(`Current dist path: ${import_picocolors13.default.dim(distPath)}`);
10188
+ import_rslog.logger.warn(`Current root path: ${import_picocolors14.default.dim(rootPath)}`);
10189
+ import_rslog.logger.warn(`Current dist path: ${import_picocolors14.default.dim(distPath)}`);
10063
10190
  }
10064
10191
  }
10065
10192
  if (cleanDistPath) {
@@ -10446,7 +10573,7 @@ async function getTemplate(entryName, config, rootPath) {
10446
10573
  if (!existTemplatePath.has(absolutePath)) {
10447
10574
  if (!await isFileExists(absolutePath)) {
10448
10575
  throw new Error(
10449
- `Failed to resolve HTML template, please check if the file exists: ${import_picocolors14.default.cyan(
10576
+ `Failed to resolve HTML template, please check if the file exists: ${import_picocolors15.default.cyan(
10450
10577
  absolutePath
10451
10578
  )}`
10452
10579
  );
@@ -10532,13 +10659,13 @@ function getChunks(entryName, entryValue) {
10532
10659
  }
10533
10660
  return chunks;
10534
10661
  }
10535
- var import_node_fs8, import_node_path27, import_picocolors14, getDefaultTemplateContent, existTemplatePath, getTagConfig, pluginHtml;
10662
+ var import_node_fs8, import_node_path27, import_picocolors15, getDefaultTemplateContent, existTemplatePath, getTagConfig, pluginHtml;
10536
10663
  var init_html = __esm({
10537
10664
  "src/plugins/html.ts"() {
10538
10665
  "use strict";
10539
10666
  import_node_fs8 = __toESM(require("fs"));
10540
10667
  import_node_path27 = __toESM(require("path"));
10541
- import_picocolors14 = __toESM(require("../compiled/picocolors/index.js"));
10668
+ import_picocolors15 = __toESM(require("../compiled/picocolors/index.js"));
10542
10669
  init_dist2();
10543
10670
  init_helpers();
10544
10671
  getDefaultTemplateContent = (mountId) => `<!doctype html><html><head></head><body><div id="${mountId}"></div></body></html>`;
@@ -10956,15 +11083,15 @@ var init_define = __esm({
10956
11083
  api.modifyBundlerChain((chain, { CHAIN_ID: CHAIN_ID2, bundler, environment }) => {
10957
11084
  const { config } = environment;
10958
11085
  const baseUrl = JSON.stringify(config.server.base);
11086
+ const assetPrefix = JSON.stringify(getPublicPathFromChain(chain, false));
10959
11087
  const builtinVars = {
10960
11088
  "import.meta.env.MODE": JSON.stringify(config.mode),
10961
11089
  "import.meta.env.DEV": config.mode === "development",
10962
11090
  "import.meta.env.PROD": config.mode === "production",
10963
11091
  "import.meta.env.BASE_URL": baseUrl,
10964
- "process.env.ASSET_PREFIX": JSON.stringify(
10965
- getPublicPathFromChain(chain, false)
10966
- ),
10967
- "process.env.BASE_URL": baseUrl
11092
+ "import.meta.env.ASSET_PREFIX": assetPrefix,
11093
+ "process.env.BASE_URL": baseUrl,
11094
+ "process.env.ASSET_PREFIX": assetPrefix
10968
11095
  };
10969
11096
  chain.plugin(CHAIN_ID2.PLUGIN.DEFINE).use(bundler.DefinePlugin, [
10970
11097
  { ...builtinVars, ...config.source.define }
@@ -11123,25 +11250,22 @@ __export(swc_exports, {
11123
11250
  });
11124
11251
  function applyScriptCondition({
11125
11252
  rule,
11126
- chain,
11253
+ isDev,
11127
11254
  config,
11128
11255
  context,
11129
- includes,
11130
- excludes
11256
+ rsbuildTarget
11131
11257
  }) {
11132
11258
  rule.include.add({
11133
11259
  and: [context.rootPath, { not: NODE_MODULES_REGEX }]
11134
11260
  });
11135
11261
  rule.include.add(/\.(?:ts|tsx|jsx|mts|cts)$/);
11136
- const target = castArray(chain.get("target"));
11137
- const legacyTarget = ["es5", "es6", "es2015", "es2016"];
11138
- if (legacyTarget.some((item) => target.includes(item))) {
11262
+ if (rsbuildTarget === "web" && isDev) {
11139
11263
  rule.include.add(/[\\/]@rsbuild[\\/]core[\\/]dist[\\/]/);
11140
11264
  }
11141
- for (const condition of [...includes, ...config.source.include || []]) {
11265
+ for (const condition of config.source.include || []) {
11142
11266
  rule.include.add(condition);
11143
11267
  }
11144
- for (const condition of [...excludes, ...config.source.exclude || []]) {
11268
+ for (const condition of config.source.exclude || []) {
11145
11269
  rule.exclude.add(condition);
11146
11270
  }
11147
11271
  }
@@ -11216,7 +11340,7 @@ var init_swc = __esm({
11216
11340
  setup(api) {
11217
11341
  api.modifyBundlerChain({
11218
11342
  order: "pre",
11219
- handler: async (chain, { CHAIN_ID: CHAIN_ID2, target, environment }) => {
11343
+ handler: async (chain, { CHAIN_ID: CHAIN_ID2, isDev, target, environment }) => {
11220
11344
  const { config, browserslist } = environment;
11221
11345
  const cacheRoot = import_node_path31.default.join(api.context.cachePath, ".swc");
11222
11346
  const rule = chain.module.rule(CHAIN_ID2.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto");
@@ -11225,11 +11349,10 @@ var init_swc = __esm({
11225
11349
  });
11226
11350
  applyScriptCondition({
11227
11351
  rule,
11228
- chain,
11352
+ isDev,
11229
11353
  config,
11230
11354
  context: api.context,
11231
- includes: [],
11232
- excludes: []
11355
+ rsbuildTarget: target
11233
11356
  });
11234
11357
  if (api.context.bundlerType === "webpack") {
11235
11358
  return;
@@ -11742,11 +11865,11 @@ var rsdoctor_exports = {};
11742
11865
  __export(rsdoctor_exports, {
11743
11866
  pluginRsdoctor: () => pluginRsdoctor
11744
11867
  });
11745
- var import_picocolors15, pluginRsdoctor;
11868
+ var import_picocolors16, pluginRsdoctor;
11746
11869
  var init_rsdoctor = __esm({
11747
11870
  "src/plugins/rsdoctor.ts"() {
11748
11871
  "use strict";
11749
- import_picocolors15 = __toESM(require("../compiled/picocolors/index.js"));
11872
+ import_picocolors16 = __toESM(require("../compiled/picocolors/index.js"));
11750
11873
  init_logger();
11751
11874
  pluginRsdoctor = () => ({
11752
11875
  name: "rsbuild:rsdoctor",
@@ -11774,7 +11897,7 @@ var init_rsdoctor = __esm({
11774
11897
  });
11775
11898
  } catch (err) {
11776
11899
  import_rslog.logger.warn(
11777
- `\`process.env.RSDOCTOR\` enabled, please install ${import_picocolors15.default.bold(import_picocolors15.default.yellow(packageName))} package.`
11900
+ `\`process.env.RSDOCTOR\` enabled, please install ${import_picocolors16.default.bold(import_picocolors16.default.yellow(packageName))} package.`
11778
11901
  );
11779
11902
  return;
11780
11903
  }
@@ -11783,7 +11906,7 @@ var init_rsdoctor = __esm({
11783
11906
  module2 = await import(packagePath);
11784
11907
  } catch (err) {
11785
11908
  import_rslog.logger.error(
11786
- `\`process.env.RSDOCTOR\` enabled, but failed to load ${import_picocolors15.default.bold(import_picocolors15.default.yellow(packageName))} module.`
11909
+ `\`process.env.RSDOCTOR\` enabled, but failed to load ${import_picocolors16.default.bold(import_picocolors16.default.yellow(packageName))} module.`
11787
11910
  );
11788
11911
  return;
11789
11912
  }
@@ -11794,7 +11917,7 @@ var init_rsdoctor = __esm({
11794
11917
  config.plugins ||= [];
11795
11918
  config.plugins.push(new module2[pluginName]());
11796
11919
  }
11797
- import_rslog.logger.info(`${import_picocolors15.default.bold(import_picocolors15.default.yellow(packageName))} enabled.`);
11920
+ import_rslog.logger.info(`${import_picocolors16.default.bold(import_picocolors16.default.yellow(packageName))} enabled.`);
11798
11921
  });
11799
11922
  }
11800
11923
  });
@@ -12925,24 +13048,44 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
12925
13048
  });
12926
13049
  const protocol = https ? "https" : "http";
12927
13050
  const urls = getAddressUrls({ protocol, port, host });
12928
- printServerURLs({
13051
+ const cliShortcutsEnabled = isCliShortcutsEnabled(config.dev);
13052
+ const closeServer = async () => {
13053
+ await Promise.all([server.close(), serverTerminator()]);
13054
+ };
13055
+ const printUrls = () => printServerURLs({
12929
13056
  urls,
12930
13057
  port,
12931
13058
  routes,
12932
13059
  protocol,
12933
- printUrls: serverConfig.printUrls
13060
+ printUrls: serverConfig.printUrls,
13061
+ trailingLineBreak: !cliShortcutsEnabled
12934
13062
  });
12935
- if (portTip && !getPortSilently) {
13063
+ const openPage = async () => {
13064
+ return open({
13065
+ https,
13066
+ port,
13067
+ routes,
13068
+ config,
13069
+ clearCache: true
13070
+ });
13071
+ };
13072
+ printUrls();
13073
+ if (cliShortcutsEnabled) {
13074
+ setupCliShortcuts({
13075
+ openPage,
13076
+ closeServer,
13077
+ printUrls,
13078
+ customShortcuts: typeof config.dev.cliShortcuts === "boolean" ? void 0 : config.dev.cliShortcuts.custom
13079
+ });
13080
+ }
13081
+ if (!getPortSilently && portTip) {
12936
13082
  import_rslog.logger.info(portTip);
12937
13083
  }
12938
- const onClose = async () => {
12939
- await Promise.all([server.close(), serverTerminator()]);
12940
- };
12941
13084
  resolve2({
12942
13085
  port,
12943
13086
  urls: urls.map((item) => item.url),
12944
13087
  server: {
12945
- close: onClose
13088
+ close: closeServer
12946
13089
  }
12947
13090
  });
12948
13091
  }
@@ -12955,9 +13098,11 @@ var init_prodServer = __esm({
12955
13098
  "use strict";
12956
13099
  init_path();
12957
13100
  init_logger();
13101
+ init_cliShortcuts();
12958
13102
  init_helper();
12959
13103
  init_httpServer();
12960
13104
  init_middlewares();
13105
+ init_open();
12961
13106
  RsbuildProdServer = class {
12962
13107
  constructor(options, middlewares) {
12963
13108
  __publicField(this, "app");
@@ -13147,12 +13292,30 @@ async function createRsbuild(options = {}) {
13147
13292
  rsbuildOptions,
13148
13293
  setCssExtractPlugin
13149
13294
  });
13150
- const preview = async (options2) => {
13295
+ const preview = async (options2 = {}) => {
13151
13296
  if (!getNodeEnv()) {
13152
13297
  setNodeEnv("production");
13153
13298
  }
13154
- const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
13155
13299
  const config = await initRsbuildConfig({ context, pluginManager });
13300
+ const { distPath } = context;
13301
+ const { checkDistDir = true } = options2;
13302
+ if (checkDistDir) {
13303
+ if (!(0, import_node_fs12.existsSync)(distPath)) {
13304
+ throw new Error(
13305
+ `The output directory ${import_picocolors17.default.yellow(
13306
+ distPath
13307
+ )} does not exist, please build the project before previewing.`
13308
+ );
13309
+ }
13310
+ if (isEmptyDir(distPath)) {
13311
+ throw new Error(
13312
+ `The output directory ${import_picocolors17.default.yellow(
13313
+ distPath
13314
+ )} is empty, please build the project before previewing.`
13315
+ );
13316
+ }
13317
+ }
13318
+ const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
13156
13319
  return startProdServer2(context, config, options2);
13157
13320
  };
13158
13321
  const build2 = (...args) => {
@@ -13234,11 +13397,13 @@ async function createRsbuild(options = {}) {
13234
13397
  }
13235
13398
  return rsbuild;
13236
13399
  }
13237
- var import_types3, getRspackProvider;
13400
+ var import_node_fs12, import_types3, import_picocolors17, getRspackProvider;
13238
13401
  var init_createRsbuild = __esm({
13239
13402
  "src/createRsbuild.ts"() {
13240
13403
  "use strict";
13404
+ import_node_fs12 = require("fs");
13241
13405
  import_types3 = require("util/types");
13406
+ import_picocolors17 = __toESM(require("../compiled/picocolors/index.js"));
13242
13407
  init_createContext();
13243
13408
  init_helpers();
13244
13409
  init_initPlugins();
@@ -13280,13 +13445,20 @@ async function init({
13280
13445
  if (configFilePath) {
13281
13446
  files.push(configFilePath);
13282
13447
  }
13283
- const { watchFiles: watchFilesConfig } = config.dev || {};
13284
- if (watchFilesConfig?.type === "reload-server") {
13285
- files.push(...castArray(watchFilesConfig.paths));
13286
- watchFiles(files, watchFilesConfig.options);
13287
- } else {
13288
- watchFiles(files);
13448
+ if (config.dev?.watchFiles) {
13449
+ for (const watchFilesConfig of castArray(config.dev.watchFiles)) {
13450
+ if (watchFilesConfig.type === "reload-page") {
13451
+ continue;
13452
+ }
13453
+ const paths = castArray(watchFilesConfig.paths);
13454
+ if (watchFilesConfig.options) {
13455
+ watchFilesForRestart(paths, watchFilesConfig.options);
13456
+ } else {
13457
+ files.push(...paths);
13458
+ }
13459
+ }
13289
13460
  }
13461
+ watchFilesForRestart(files);
13290
13462
  }
13291
13463
  const { createRsbuild: createRsbuild2 } = await Promise.resolve().then(() => (init_createRsbuild(), createRsbuild_exports));
13292
13464
  config.source ||= {};
@@ -13312,6 +13484,10 @@ async function init({
13312
13484
  config.server ||= {};
13313
13485
  config.server.port = commonOpts.port;
13314
13486
  }
13487
+ if (config.dev?.cliShortcuts === void 0) {
13488
+ config.dev ||= {};
13489
+ config.dev.cliShortcuts = true;
13490
+ }
13315
13491
  return createRsbuild2({
13316
13492
  cwd: root,
13317
13493
  rsbuildConfig: config,
@@ -13347,7 +13523,7 @@ var init_init = __esm({
13347
13523
 
13348
13524
  // src/cli/commands.ts
13349
13525
  function runCli() {
13350
- program.name("rsbuild").usage("<command> [options]").version("1.0.10");
13526
+ program.name("rsbuild").usage("<command> [options]").version("1.0.11");
13351
13527
  const devCommand = program.command("dev");
13352
13528
  const buildCommand = program.command("build");
13353
13529
  const previewCommand = program.command("preview");
@@ -13381,24 +13557,6 @@ function runCli() {
13381
13557
  previewCommand.description("preview the production build locally").action(async (options) => {
13382
13558
  try {
13383
13559
  const rsbuild = await init({ cliOptions: options });
13384
- await rsbuild?.initConfigs();
13385
- if (rsbuild) {
13386
- const { distPath } = rsbuild.context;
13387
- if (!(0, import_node_fs12.existsSync)(distPath)) {
13388
- throw new Error(
13389
- `The output directory ${import_picocolors16.default.yellow(
13390
- distPath
13391
- )} does not exist, please build the project before previewing.`
13392
- );
13393
- }
13394
- if (isEmptyDir(distPath)) {
13395
- throw new Error(
13396
- `The output directory ${import_picocolors16.default.yellow(
13397
- distPath
13398
- )} is empty, please build the project before previewing.`
13399
- );
13400
- }
13401
- }
13402
13560
  await rsbuild?.preview();
13403
13561
  } catch (err) {
13404
13562
  import_rslog.logger.error("Failed to start preview server.");
@@ -13422,14 +13580,11 @@ function runCli() {
13422
13580
  });
13423
13581
  program.parse();
13424
13582
  }
13425
- var import_node_fs12, import_picocolors16, applyCommonOptions, applyServerOptions;
13583
+ var applyCommonOptions, applyServerOptions;
13426
13584
  var init_commands = __esm({
13427
13585
  "src/cli/commands.ts"() {
13428
13586
  "use strict";
13429
- import_node_fs12 = require("fs");
13430
13587
  init_esm();
13431
- import_picocolors16 = __toESM(require("../compiled/picocolors/index.js"));
13432
- init_helpers();
13433
13588
  init_logger();
13434
13589
  init_init();
13435
13590
  applyCommonOptions = (command) => {
@@ -13477,7 +13632,7 @@ function prepareCli() {
13477
13632
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
13478
13633
  console.log();
13479
13634
  }
13480
- import_rslog.logger.greet(` ${`Rsbuild v${"1.0.10"}`}
13635
+ import_rslog.logger.greet(` ${`Rsbuild v${"1.0.11"}`}
13481
13636
  `);
13482
13637
  }
13483
13638
  var import_node_module;
@@ -13563,7 +13718,7 @@ init_logger();
13563
13718
  init_mergeConfig();
13564
13719
  init_helpers();
13565
13720
  init_constants();
13566
- var version = "1.0.10";
13721
+ var version = "1.0.11";
13567
13722
  // Annotate the CommonJS export names for ESM import in node:
13568
13723
  0 && (module.exports = {
13569
13724
  PLUGIN_CSS_NAME,