@rsbuild/core 0.7.3 → 0.7.5

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
@@ -114,19 +114,53 @@ var init_format = __esm({
114
114
  });
115
115
 
116
116
  // src/constants.ts
117
- var import_node_path, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HTML_REGEX, CSS_REGEX;
117
+ var import_node_path, ROOT_DIST_DIR, HTML_DIST_DIR, SERVER_DIST_DIR, SERVICE_WORKER_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, DEFAULT_PORT, DEFAULT_DATA_URL_SIZE, DEFAULT_MOUNT_ID, DEFAULT_DEV_HOST, HTML_REGEX, CSS_REGEX, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, FONT_EXTENSIONS, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, AUDIO_EXTENSIONS;
118
118
  var init_constants = __esm({
119
119
  "src/constants.ts"() {
120
120
  "use strict";
121
121
  import_node_path = require("path");
122
- PLUGIN_SWC_NAME = "rsbuild:swc";
123
- PLUGIN_CSS_NAME = "rsbuild:css";
122
+ ROOT_DIST_DIR = "dist";
123
+ HTML_DIST_DIR = "/";
124
+ SERVER_DIST_DIR = "server";
125
+ SERVICE_WORKER_DIST_DIR = "worker";
126
+ JS_DIST_DIR = "static/js";
127
+ CSS_DIST_DIR = "static/css";
128
+ SVG_DIST_DIR = "static/svg";
129
+ FONT_DIST_DIR = "static/font";
130
+ WASM_DIST_DIR = "static/wasm";
131
+ IMAGE_DIST_DIR = "static/image";
132
+ MEDIA_DIST_DIR = "static/media";
124
133
  LOADER_PATH = (0, import_node_path.join)(__dirname);
125
134
  STATIC_PATH = (0, import_node_path.join)(__dirname, "../static");
126
135
  COMPILED_PATH = (0, import_node_path.join)(__dirname, "../compiled");
127
136
  TS_CONFIG_FILE = "tsconfig.json";
137
+ DEFAULT_PORT = 3e3;
138
+ DEFAULT_DATA_URL_SIZE = 4096;
139
+ DEFAULT_MOUNT_ID = "root";
140
+ DEFAULT_DEV_HOST = "0.0.0.0";
128
141
  HTML_REGEX = /\.html$/;
129
142
  CSS_REGEX = /\.css$/;
143
+ PLUGIN_SWC_NAME = "rsbuild:swc";
144
+ PLUGIN_CSS_NAME = "rsbuild:css";
145
+ FONT_EXTENSIONS = ["woff", "woff2", "eot", "ttf", "otf", "ttc"];
146
+ IMAGE_EXTENSIONS = [
147
+ "png",
148
+ "jpg",
149
+ "jpeg",
150
+ "pjpeg",
151
+ "pjp",
152
+ "gif",
153
+ "bmp",
154
+ "webp",
155
+ "ico",
156
+ "apng",
157
+ "avif",
158
+ "tif",
159
+ "tiff",
160
+ "jfif"
161
+ ];
162
+ VIDEO_EXTENSIONS = ["mp4", "webm", "ogg", "mov"];
163
+ AUDIO_EXTENSIONS = ["mp3", "wav", "flac", "aac", "m4a", "opus"];
130
164
  }
131
165
  });
132
166
 
@@ -355,6 +389,7 @@ var init_mergeConfig = __esm({
355
389
  "output.cssModules.auto",
356
390
  "output.targets",
357
391
  "output.emitAssets",
392
+ "server.open",
358
393
  "server.printUrls",
359
394
  "dev.startUrl",
360
395
  "provider"
@@ -541,6 +576,55 @@ async function loadConfig({
541
576
  throw err;
542
577
  }
543
578
  }
579
+ async function outputInspectConfigFiles({
580
+ rsbuildConfig,
581
+ rawRsbuildConfig,
582
+ bundlerConfigs,
583
+ inspectOptions,
584
+ configType
585
+ }) {
586
+ const { outputPath } = inspectOptions;
587
+ const files = [
588
+ {
589
+ path: (0, import_node_path4.join)(outputPath, "rsbuild.config.mjs"),
590
+ label: "Rsbuild Config",
591
+ content: rawRsbuildConfig
592
+ },
593
+ ...bundlerConfigs.map((content, index) => {
594
+ const suffix = rsbuildConfig.output.targets[index];
595
+ const outputFile = `${configType}.config.${suffix}.mjs`;
596
+ let outputFilePath = (0, import_node_path4.join)(outputPath, outputFile);
597
+ if (import_shared5.fse.existsSync(outputFilePath)) {
598
+ outputFilePath = outputFilePath.replace(/\.mjs$/, `.${Date.now()}.mjs`);
599
+ }
600
+ return {
601
+ path: outputFilePath,
602
+ label: `${(0, import_shared5.upperFirst)(configType)} Config (${suffix})`,
603
+ content
604
+ };
605
+ })
606
+ ];
607
+ await Promise.all(
608
+ files.map(
609
+ (item) => import_shared5.fse.outputFile(item.path, `export default ${item.content}`)
610
+ )
611
+ );
612
+ const fileInfos = files.map(
613
+ (item) => ` - ${import_shared5.color.bold(import_shared5.color.yellow(item.label))}: ${import_shared5.color.underline(
614
+ item.path
615
+ )}`
616
+ ).join("\n");
617
+ import_shared5.logger.success(
618
+ `Inspect config succeed, open following files to view the content:
619
+
620
+ ${fileInfos}
621
+ `
622
+ );
623
+ }
624
+ async function stringifyConfig(config, verbose) {
625
+ const stringify = import_shared5.RspackChain.toString;
626
+ return stringify(config, { verbose });
627
+ }
544
628
  var import_node_fs, import_node_path4, import_shared5, getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath;
545
629
  var init_config = __esm({
546
630
  "src/config.ts"() {
@@ -562,8 +646,9 @@ var init_config = __esm({
562
646
  }
563
647
  });
564
648
  getDefaultServerConfig = () => ({
565
- port: import_shared5.DEFAULT_PORT,
566
- host: import_shared5.DEFAULT_DEV_HOST,
649
+ port: DEFAULT_PORT,
650
+ host: DEFAULT_DEV_HOST,
651
+ open: false,
567
652
  htmlFallback: "index",
568
653
  compress: true,
569
654
  printUrls: true,
@@ -590,7 +675,7 @@ var init_config = __esm({
590
675
  },
591
676
  title: "Rsbuild App",
592
677
  inject: "head",
593
- mountId: import_shared5.DEFAULT_MOUNT_ID,
678
+ mountId: DEFAULT_MOUNT_ID,
594
679
  crossorigin: false,
595
680
  outputStructure: "flat",
596
681
  scriptLoading: "defer"
@@ -622,27 +707,27 @@ var init_config = __esm({
622
707
  getDefaultOutputConfig = () => ({
623
708
  targets: ["web"],
624
709
  distPath: {
625
- root: import_shared5.ROOT_DIST_DIR,
626
- js: import_shared5.JS_DIST_DIR,
627
- css: import_shared5.CSS_DIST_DIR,
628
- svg: import_shared5.SVG_DIST_DIR,
629
- font: import_shared5.FONT_DIST_DIR,
630
- html: import_shared5.HTML_DIST_DIR,
631
- wasm: import_shared5.WASM_DIST_DIR,
632
- image: import_shared5.IMAGE_DIST_DIR,
633
- media: import_shared5.MEDIA_DIST_DIR,
634
- server: import_shared5.SERVER_DIST_DIR,
635
- worker: import_shared5.SERVICE_WORKER_DIST_DIR
710
+ root: ROOT_DIST_DIR,
711
+ js: JS_DIST_DIR,
712
+ css: CSS_DIST_DIR,
713
+ svg: SVG_DIST_DIR,
714
+ font: FONT_DIST_DIR,
715
+ html: HTML_DIST_DIR,
716
+ wasm: WASM_DIST_DIR,
717
+ image: IMAGE_DIST_DIR,
718
+ media: MEDIA_DIST_DIR,
719
+ server: SERVER_DIST_DIR,
720
+ worker: SERVICE_WORKER_DIST_DIR
636
721
  },
637
722
  assetPrefix: import_shared5.DEFAULT_ASSET_PREFIX,
638
723
  filename: {},
639
724
  charset: "ascii",
640
725
  polyfill: "usage",
641
726
  dataUriLimit: {
642
- svg: import_shared5.DEFAULT_DATA_URL_SIZE,
643
- font: import_shared5.DEFAULT_DATA_URL_SIZE,
644
- image: import_shared5.DEFAULT_DATA_URL_SIZE,
645
- media: import_shared5.DEFAULT_DATA_URL_SIZE
727
+ svg: DEFAULT_DATA_URL_SIZE,
728
+ font: DEFAULT_DATA_URL_SIZE,
729
+ image: DEFAULT_DATA_URL_SIZE,
730
+ media: DEFAULT_DATA_URL_SIZE
646
731
  },
647
732
  legalComments: "linked",
648
733
  injectStyles: false,
@@ -918,7 +1003,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
918
1003
  return {
919
1004
  entry: getEntryObject(config, "web"),
920
1005
  targets: config.output?.targets || [],
921
- version: "0.7.3",
1006
+ version: "0.7.5",
922
1007
  rootPath,
923
1008
  distPath,
924
1009
  cachePath,
@@ -1335,13 +1420,13 @@ async function inspectConfig({
1335
1420
  ...context.normalizedConfig,
1336
1421
  pluginNames: pluginManager.getPlugins().map((p) => p.name)
1337
1422
  };
1338
- const rawRsbuildConfig = await (0, import_shared12.stringifyConfig)(
1423
+ const rawRsbuildConfig = await stringifyConfig(
1339
1424
  rsbuildDebugConfig,
1340
1425
  inspectOptions.verbose
1341
1426
  );
1342
1427
  const rawBundlerConfigs = await Promise.all(
1343
1428
  rspackConfigs.map(
1344
- (config) => (0, import_shared12.stringifyConfig)(config, inspectOptions.verbose)
1429
+ (config) => stringifyConfig(config, inspectOptions.verbose)
1345
1430
  )
1346
1431
  );
1347
1432
  let outputPath = inspectOptions.outputPath || context.distPath;
@@ -1349,7 +1434,7 @@ async function inspectConfig({
1349
1434
  outputPath = (0, import_node_path8.join)(context.rootPath, outputPath);
1350
1435
  }
1351
1436
  if (inspectOptions.writeToDisk) {
1352
- await (0, import_shared12.outputInspectConfigFiles)({
1437
+ await outputInspectConfigFiles({
1353
1438
  rsbuildConfig: context.normalizedConfig,
1354
1439
  rawRsbuildConfig,
1355
1440
  bundlerConfigs: rawBundlerConfigs,
@@ -1375,6 +1460,7 @@ var init_inspectConfig = __esm({
1375
1460
  "use strict";
1376
1461
  import_node_path8 = require("path");
1377
1462
  import_shared12 = require("@rsbuild/shared");
1463
+ init_config();
1378
1464
  init_initConfigs();
1379
1465
  }
1380
1466
  });
@@ -2163,6 +2249,7 @@ var init_helper = __esm({
2163
2249
  import_node_net = __toESM(require("net"));
2164
2250
  import_node_os = __toESM(require("os"));
2165
2251
  import_shared20 = require("@rsbuild/shared");
2252
+ init_constants();
2166
2253
  formatPrefix = (prefix) => {
2167
2254
  if (!prefix) {
2168
2255
  return "/";
@@ -2237,10 +2324,10 @@ var init_helper = __esm({
2237
2324
  config,
2238
2325
  getPortSilently
2239
2326
  }) => {
2240
- const host = config.server.host || import_shared20.DEFAULT_DEV_HOST;
2327
+ const host = config.server.host || DEFAULT_DEV_HOST;
2241
2328
  const port = await getPort({
2242
2329
  host,
2243
- port: config.server.port || import_shared20.DEFAULT_PORT,
2330
+ port: config.server.port || DEFAULT_PORT,
2244
2331
  strictPort: config.server.strictPort || false,
2245
2332
  silent: getPortSilently
2246
2333
  });
@@ -2314,7 +2401,7 @@ var init_helper = __esm({
2314
2401
  port,
2315
2402
  host
2316
2403
  }) => {
2317
- if (host && host !== import_shared20.DEFAULT_DEV_HOST) {
2404
+ if (host && host !== DEFAULT_DEV_HOST) {
2318
2405
  return [
2319
2406
  {
2320
2407
  label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
@@ -2776,7 +2863,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2776
2863
  dev: devConfig,
2777
2864
  server: serverConfig,
2778
2865
  output: {
2779
- distPath: config.output.distPath.root || import_shared22.ROOT_DIST_DIR
2866
+ distPath: config.output.distPath.root || ROOT_DIST_DIR
2780
2867
  },
2781
2868
  outputFileSystem
2782
2869
  });
@@ -2851,6 +2938,7 @@ var init_devServer = __esm({
2851
2938
  "use strict";
2852
2939
  import_node_fs3 = __toESM(require("fs"));
2853
2940
  import_shared22 = require("@rsbuild/shared");
2941
+ init_constants();
2854
2942
  init_getDevMiddlewares();
2855
2943
  init_helper();
2856
2944
  init_httpServer();
@@ -2881,7 +2969,7 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
2881
2969
  {
2882
2970
  pwd: context.rootPath,
2883
2971
  output: {
2884
- path: config.output.distPath.root || import_shared23.ROOT_DIST_DIR,
2972
+ path: config.output.distPath.root || ROOT_DIST_DIR,
2885
2973
  assetPrefix: config.output.assetPrefix
2886
2974
  },
2887
2975
  serverConfig
@@ -2942,6 +3030,7 @@ var init_prodServer = __esm({
2942
3030
  "use strict";
2943
3031
  import_node_path11 = require("path");
2944
3032
  import_shared23 = require("@rsbuild/shared");
3033
+ init_constants();
2945
3034
  init_helper();
2946
3035
  init_httpServer();
2947
3036
  init_middlewares();
@@ -3618,9 +3707,9 @@ function getPublicPath({
3618
3707
  publicPath = dev.assetPrefix;
3619
3708
  } else if (dev.assetPrefix === true) {
3620
3709
  const protocol = context.devServer?.https ? "https" : "http";
3621
- const hostname = context.devServer?.hostname || import_shared29.DEFAULT_DEV_HOST;
3622
- const port = context.devServer?.port || import_shared29.DEFAULT_PORT;
3623
- if (hostname === import_shared29.DEFAULT_DEV_HOST) {
3710
+ const hostname = context.devServer?.hostname || DEFAULT_DEV_HOST;
3711
+ const port = context.devServer?.port || DEFAULT_PORT;
3712
+ if (hostname === DEFAULT_DEV_HOST) {
3624
3713
  const localHostname = "localhost";
3625
3714
  publicPath = `${protocol}://${localHostname}:${port}/`;
3626
3715
  } else {
@@ -3636,6 +3725,7 @@ var init_output = __esm({
3636
3725
  import_node_path15 = require("path");
3637
3726
  import_shared29 = require("@rsbuild/shared");
3638
3727
  import_core5 = require("@rspack/core");
3728
+ init_constants();
3639
3729
  init_helpers();
3640
3730
  init_pluginHelper();
3641
3731
  init_css();
@@ -3653,7 +3743,18 @@ var init_output = __esm({
3653
3743
  const jsPath = (0, import_shared29.getDistPath)(config, "js");
3654
3744
  const jsAsyncPath = (0, import_shared29.getDistPath)(config, "jsAsync");
3655
3745
  const jsFilename = (0, import_shared29.getFilename)(config, "js", isProd5);
3656
- chain.output.path(api.context.distPath).filename(import_node_path15.posix.join(jsPath, jsFilename)).chunkFilename(import_node_path15.posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3746
+ const isJsFilenameFn = typeof jsFilename === "function";
3747
+ chain.output.path(api.context.distPath).filename(
3748
+ isJsFilenameFn ? (...args) => {
3749
+ const name = jsFilename(...args);
3750
+ return import_node_path15.posix.join(jsPath, name);
3751
+ } : import_node_path15.posix.join(jsPath, jsFilename)
3752
+ ).chunkFilename(
3753
+ isJsFilenameFn ? (...args) => {
3754
+ const name = jsFilename(...args);
3755
+ return import_node_path15.posix.join(jsAsyncPath, name);
3756
+ } : import_node_path15.posix.join(jsAsyncPath, jsFilename)
3757
+ ).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3657
3758
  if (isServer) {
3658
3759
  const serverPath = (0, import_shared29.getDistPath)(config, "server");
3659
3760
  chain.output.path(import_node_path15.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
@@ -4025,6 +4126,7 @@ var init_asset = __esm({
4025
4126
  "use strict";
4026
4127
  import_node_path18 = __toESM(require("path"));
4027
4128
  import_shared34 = require("@rsbuild/shared");
4129
+ init_constants();
4028
4130
  chainStaticAssetRule = ({
4029
4131
  emit,
4030
4132
  rule,
@@ -4067,14 +4169,14 @@ var init_asset = __esm({
4067
4169
  });
4068
4170
  };
4069
4171
  const emit = config.output.emitAssets({ target });
4070
- createAssetRule("image", import_shared34.IMAGE_EXTENSIONS, emit);
4172
+ createAssetRule("image", IMAGE_EXTENSIONS, emit);
4071
4173
  createAssetRule("svg", ["svg"], emit);
4072
4174
  createAssetRule(
4073
4175
  "media",
4074
- [...import_shared34.VIDEO_EXTENSIONS, ...import_shared34.AUDIO_EXTENSIONS],
4176
+ [...VIDEO_EXTENSIONS, ...AUDIO_EXTENSIONS],
4075
4177
  emit
4076
4178
  );
4077
- createAssetRule("font", import_shared34.FONT_EXTENSIONS, emit);
4179
+ createAssetRule("font", FONT_EXTENSIONS, emit);
4078
4180
  });
4079
4181
  }
4080
4182
  });
@@ -4371,20 +4473,18 @@ var init_HtmlBasicPlugin = __esm({
4371
4473
  addTitleTag(headTags, data.plugin.options?.title);
4372
4474
  }
4373
4475
  addFavicon(headTags, favicon);
4374
- const result = await this.modifyTagsFn(
4375
- {
4376
- headTags: headTags.map(formatBasicTag),
4377
- bodyTags: bodyTags.map(formatBasicTag)
4378
- },
4379
- {
4380
- compilation,
4381
- assetPrefix: data.publicPath,
4382
- filename: data.outputName
4383
- }
4384
- );
4476
+ const tags = {
4477
+ headTags: headTags.map(formatBasicTag),
4478
+ bodyTags: bodyTags.map(formatBasicTag)
4479
+ };
4480
+ const modified = this.modifyTagsFn ? await this.modifyTagsFn(tags, {
4481
+ compilation,
4482
+ assetPrefix: data.publicPath,
4483
+ filename: data.outputName
4484
+ }) : tags;
4385
4485
  Object.assign(data, {
4386
- headTags: result.headTags.map(fromBasicTag),
4387
- bodyTags: result.bodyTags.map(fromBasicTag)
4486
+ headTags: modified.headTags.map(fromBasicTag),
4487
+ bodyTags: modified.bodyTags.map(fromBasicTag)
4388
4488
  });
4389
4489
  if (tagConfig) {
4390
4490
  const hash = compilation.hash ?? "";
@@ -4978,7 +5078,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
4978
5078
  }
4979
5079
  };
4980
5080
  }
4981
- async function applyCoreJs(swcConfig, chain, polyfillMode) {
5081
+ async function applyCoreJs(swcConfig, polyfillMode) {
4982
5082
  const coreJsPath = require.resolve("core-js/package.json");
4983
5083
  const version2 = (0, import_shared42.getCoreJsVersion)(coreJsPath);
4984
5084
  const coreJsDir = import_node_path23.default.dirname(coreJsPath);
@@ -4986,9 +5086,7 @@ async function applyCoreJs(swcConfig, chain, polyfillMode) {
4986
5086
  if (polyfillMode === "usage") {
4987
5087
  swcConfig.env.shippedProposals = true;
4988
5088
  }
4989
- chain.resolve.alias.merge({
4990
- "core-js": coreJsDir
4991
- });
5089
+ return coreJsDir;
4992
5090
  }
4993
5091
  function applyTransformImport(swcConfig, pluginImport) {
4994
5092
  if (pluginImport !== false && pluginImport) {
@@ -5034,6 +5132,9 @@ var init_swc = __esm({
5034
5132
  handler: async (chain, { CHAIN_ID: CHAIN_ID3, target }) => {
5035
5133
  const config = api.getNormalizedConfig();
5036
5134
  const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared42.SCRIPT_REGEX).type("javascript/auto");
5135
+ const dataUriRule = chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
5136
+ or: ["text/javascript", "application/javascript"]
5137
+ });
5037
5138
  (0, import_shared42.applyScriptCondition)({
5038
5139
  rule,
5039
5140
  chain,
@@ -5061,7 +5162,10 @@ var init_swc = __esm({
5061
5162
  swcConfig.env.mode = void 0;
5062
5163
  } else {
5063
5164
  swcConfig.env.mode = polyfillMode;
5064
- await applyCoreJs(swcConfig, chain, polyfillMode);
5165
+ const coreJsDir = await applyCoreJs(swcConfig, polyfillMode);
5166
+ for (const item of [rule, dataUriRule]) {
5167
+ item.resolve.alias.set("core-js", coreJsDir);
5168
+ }
5065
5169
  }
5066
5170
  }
5067
5171
  const mergedSwcConfig = (0, import_shared42.reduceConfigs)({
@@ -5070,9 +5174,7 @@ var init_swc = __esm({
5070
5174
  mergeFn: import_shared42.deepmerge
5071
5175
  });
5072
5176
  rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
5073
- chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
5074
- or: ["text/javascript", "application/javascript"]
5075
- }).resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared42.cloneDeep)(mergedSwcConfig));
5177
+ dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared42.cloneDeep)(mergedSwcConfig));
5076
5178
  }
5077
5179
  });
5078
5180
  }
@@ -5310,10 +5412,7 @@ var init_splitChunks = __esm({
5310
5412
  rootPath: api.context.rootPath,
5311
5413
  polyfill: config.output.polyfill
5312
5414
  });
5313
- chain.optimization.splitChunks(
5314
- // @ts-expect-error splitChunks type mismatch
5315
- splitChunksOptions
5316
- );
5415
+ chain.optimization.splitChunks(splitChunksOptions);
5317
5416
  }
5318
5417
  );
5319
5418
  }
@@ -5321,12 +5420,13 @@ var init_splitChunks = __esm({
5321
5420
  }
5322
5421
  });
5323
5422
 
5324
- // src/plugins/startUrl.ts
5325
- var startUrl_exports = {};
5326
- __export(startUrl_exports, {
5423
+ // src/plugins/open.ts
5424
+ var open_exports = {};
5425
+ __export(open_exports, {
5327
5426
  openBrowser: () => openBrowser,
5328
- pluginStartUrl: () => pluginStartUrl,
5329
- replacePlaceholder: () => replacePlaceholder
5427
+ pluginOpen: () => pluginOpen,
5428
+ replacePlaceholder: () => replacePlaceholder,
5429
+ resolveUrl: () => resolveUrl
5330
5430
  });
5331
5431
  async function openBrowser(url2) {
5332
5432
  const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
@@ -5360,30 +5460,44 @@ async function openBrowser(url2) {
5360
5460
  return false;
5361
5461
  }
5362
5462
  }
5363
- function pluginStartUrl() {
5463
+ function resolveUrl(str, base) {
5464
+ if ((0, import_shared44.canParse)(str)) {
5465
+ return str;
5466
+ }
5467
+ try {
5468
+ const url2 = new URL(str, base);
5469
+ return url2.href;
5470
+ } catch (e) {
5471
+ throw new Error(
5472
+ "[rsbuild:open]: Invalid input: not a valid URL or pathname"
5473
+ );
5474
+ }
5475
+ }
5476
+ function pluginOpen() {
5364
5477
  return {
5365
- name: "rsbuild:start-url",
5478
+ name: "rsbuild:open",
5366
5479
  setup(api) {
5367
5480
  const onStartServer = async (params) => {
5368
5481
  const { port, routes } = params;
5369
5482
  const config = api.getNormalizedConfig();
5370
- const { startUrl, beforeStartUrl } = config.dev;
5371
5483
  const { https } = api.context.devServer || {};
5484
+ const { targets, before } = normalizeOpenConfig(config);
5372
5485
  const isCodesandbox = process.env.CSB === "true";
5373
- const shouldOpen = Boolean(startUrl) && !isCodesandbox;
5486
+ const shouldOpen = targets !== void 0 && !isCodesandbox;
5374
5487
  if (!shouldOpen) {
5375
5488
  return;
5376
5489
  }
5377
5490
  const urls = [];
5378
- if (startUrl === true || !startUrl) {
5379
- const protocol = https ? "https" : "http";
5491
+ const protocol = https ? "https" : "http";
5492
+ const baseUrl = `${protocol}://localhost:${port}`;
5493
+ if (!targets.length) {
5380
5494
  if (routes.length) {
5381
- urls.push(`${protocol}://localhost:${port}${routes[0].pathname}`);
5495
+ urls.push(`${baseUrl}${routes[0].pathname}`);
5382
5496
  }
5383
5497
  } else {
5384
5498
  urls.push(
5385
- ...(0, import_shared44.castArray)(startUrl).map(
5386
- (item) => replacePlaceholder(item, port)
5499
+ ...targets.map(
5500
+ (target) => resolveUrl(replacePlaceholder(target, port), baseUrl)
5387
5501
  )
5388
5502
  );
5389
5503
  }
@@ -5395,22 +5509,19 @@ function pluginStartUrl() {
5395
5509
  }
5396
5510
  }
5397
5511
  };
5398
- if (beforeStartUrl) {
5399
- Promise.all((0, import_shared44.castArray)(beforeStartUrl).map((fn) => fn())).then(
5400
- openUrls
5401
- );
5402
- } else {
5403
- openUrls();
5512
+ if (before) {
5513
+ await before();
5404
5514
  }
5515
+ openUrls();
5405
5516
  };
5406
5517
  api.onAfterStartDevServer(onStartServer);
5407
5518
  api.onAfterStartProdServer(onStartServer);
5408
5519
  }
5409
5520
  };
5410
5521
  }
5411
- var import_node_child_process, import_node_util, import_shared44, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs;
5412
- var init_startUrl = __esm({
5413
- "src/plugins/startUrl.ts"() {
5522
+ var import_node_child_process, import_node_util, import_shared44, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs, normalizeOpenConfig;
5523
+ var init_open = __esm({
5524
+ "src/plugins/open.ts"() {
5414
5525
  "use strict";
5415
5526
  import_node_child_process = require("child_process");
5416
5527
  import_node_util = require("util");
@@ -5437,6 +5548,26 @@ var init_startUrl = __esm({
5437
5548
  };
5438
5549
  replacePlaceholder = (url2, port) => url2.replace(/<port>/g, String(port));
5439
5550
  openedURLs = [];
5551
+ normalizeOpenConfig = (config) => {
5552
+ const open = config.server.open || config.dev.startUrl;
5553
+ const { beforeStartUrl } = config.dev;
5554
+ if (open === false) {
5555
+ return {};
5556
+ }
5557
+ if (open === true) {
5558
+ return { targets: [], before: beforeStartUrl };
5559
+ }
5560
+ if (typeof open === "string") {
5561
+ return { targets: [open], before: beforeStartUrl };
5562
+ }
5563
+ if (Array.isArray(open)) {
5564
+ return { targets: open, before: beforeStartUrl };
5565
+ }
5566
+ return {
5567
+ targets: open.target ? (0, import_shared44.castArray)(open.target) : [],
5568
+ before: open.before
5569
+ };
5570
+ };
5440
5571
  }
5441
5572
  });
5442
5573
 
@@ -5818,16 +5949,16 @@ function determineAsValue({
5818
5949
  if (["css"].includes(extension)) {
5819
5950
  return "style";
5820
5951
  }
5821
- if (import_shared49.IMAGE_EXTENSIONS.includes(extension)) {
5952
+ if (IMAGE_EXTENSIONS.includes(extension)) {
5822
5953
  return "image";
5823
5954
  }
5824
- if (import_shared49.VIDEO_EXTENSIONS.includes(extension)) {
5955
+ if (VIDEO_EXTENSIONS.includes(extension)) {
5825
5956
  return "video";
5826
5957
  }
5827
- if (import_shared49.AUDIO_EXTENSIONS.includes(extension)) {
5958
+ if (AUDIO_EXTENSIONS.includes(extension)) {
5828
5959
  return "audio";
5829
5960
  }
5830
- if (import_shared49.FONT_EXTENSIONS.includes(extension)) {
5961
+ if (FONT_EXTENSIONS.includes(extension)) {
5831
5962
  return "font";
5832
5963
  }
5833
5964
  if (["vtt"].includes(extension)) {
@@ -5835,13 +5966,13 @@ function determineAsValue({
5835
5966
  }
5836
5967
  return "script";
5837
5968
  }
5838
- var import_node_path25, import_node_url3, import_shared49;
5969
+ var import_node_path25, import_node_url3;
5839
5970
  var init_determineAsValue = __esm({
5840
5971
  "src/rspack/preload/helpers/determineAsValue.ts"() {
5841
5972
  "use strict";
5842
5973
  import_node_path25 = __toESM(require("path"));
5843
5974
  import_node_url3 = require("url");
5844
- import_shared49 = require("@rsbuild/shared");
5975
+ init_constants();
5845
5976
  }
5846
5977
  });
5847
5978
 
@@ -5949,10 +6080,10 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
5949
6080
  );
5950
6081
  const sortedFilteredFiles = filteredFiles.sort();
5951
6082
  const links = [];
5952
- const publicPath = (0, import_shared50.getPublicPathFromCompiler)(compilation.compiler);
6083
+ const publicPath = (0, import_shared49.getPublicPathFromCompiler)(compilation.compiler);
5953
6084
  const { crossOriginLoading } = compilation.compiler.options.output;
5954
6085
  for (const file of sortedFilteredFiles) {
5955
- const href = (0, import_shared50.withPublicPath)(file, publicPath);
6086
+ const href = (0, import_shared49.withPublicPath)(file, publicPath);
5956
6087
  const attributes = {
5957
6088
  href,
5958
6089
  rel: type
@@ -5980,11 +6111,11 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
5980
6111
  }
5981
6112
  return links;
5982
6113
  }
5983
- var import_shared50, defaultOptions, HtmlPreloadOrPrefetchPlugin;
6114
+ var import_shared49, defaultOptions, HtmlPreloadOrPrefetchPlugin;
5984
6115
  var init_HtmlPreloadOrPrefetchPlugin = __esm({
5985
6116
  "src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
5986
6117
  "use strict";
5987
- import_shared50 = require("@rsbuild/shared");
6118
+ import_shared49 = require("@rsbuild/shared");
5988
6119
  init_pluginHelper();
5989
6120
  init_helpers2();
5990
6121
  defaultOptions = {
@@ -6006,7 +6137,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6006
6137
  apply(compiler) {
6007
6138
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
6008
6139
  getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
6009
- `HTML${(0, import_shared50.upperFirst)(this.type)}Plugin`,
6140
+ `HTML${(0, import_shared49.upperFirst)(this.type)}Plugin`,
6010
6141
  (htmlPluginData) => {
6011
6142
  this.resourceHints = generateLinks(
6012
6143
  this.options,
@@ -6019,7 +6150,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6019
6150
  }
6020
6151
  );
6021
6152
  getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
6022
- `HTML${(0, import_shared50.upperFirst)(this.type)}Plugin`,
6153
+ `HTML${(0, import_shared49.upperFirst)(this.type)}Plugin`,
6023
6154
  (htmlPluginData) => {
6024
6155
  if (this.resourceHints) {
6025
6156
  htmlPluginData.assetTags.styles = [
@@ -6044,11 +6175,11 @@ var resourceHints_exports = {};
6044
6175
  __export(resourceHints_exports, {
6045
6176
  pluginResourceHints: () => pluginResourceHints
6046
6177
  });
6047
- var import_shared51, generateLinks2, pluginResourceHints;
6178
+ var import_shared50, generateLinks2, pluginResourceHints;
6048
6179
  var init_resourceHints = __esm({
6049
6180
  "src/plugins/resourceHints.ts"() {
6050
6181
  "use strict";
6051
- import_shared51 = require("@rsbuild/shared");
6182
+ import_shared50 = require("@rsbuild/shared");
6052
6183
  generateLinks2 = (options, rel) => options.map((option) => ({
6053
6184
  tag: "link",
6054
6185
  attrs: {
@@ -6083,7 +6214,7 @@ var init_resourceHints = __esm({
6083
6214
  const {
6084
6215
  performance: { preload, prefetch }
6085
6216
  } = config;
6086
- if ((0, import_shared51.isHtmlDisabled)(config, target)) {
6217
+ if ((0, import_shared50.isHtmlDisabled)(config, target)) {
6087
6218
  return;
6088
6219
  }
6089
6220
  const HTMLCount = chain.entryPoints.values().length;
@@ -6146,12 +6277,12 @@ var server_exports = {};
6146
6277
  __export(server_exports, {
6147
6278
  pluginServer: () => pluginServer
6148
6279
  });
6149
- var import_node_path26, import_shared52, pluginServer;
6280
+ var import_node_path26, import_shared51, pluginServer;
6150
6281
  var init_server = __esm({
6151
6282
  "src/plugins/server.ts"() {
6152
6283
  "use strict";
6153
6284
  import_node_path26 = require("path");
6154
- import_shared52 = require("@rsbuild/shared");
6285
+ import_shared51 = require("@rsbuild/shared");
6155
6286
  pluginServer = () => ({
6156
6287
  name: "rsbuild:server",
6157
6288
  setup(api) {
@@ -6163,11 +6294,11 @@ var init_server = __esm({
6163
6294
  return;
6164
6295
  }
6165
6296
  const publicDir = (0, import_node_path26.isAbsolute)(name) ? name : (0, import_node_path26.join)(api.context.rootPath, name);
6166
- if (!import_shared52.fse.existsSync(publicDir)) {
6297
+ if (!import_shared51.fse.existsSync(publicDir)) {
6167
6298
  return;
6168
6299
  }
6169
6300
  try {
6170
- await import_shared52.fse.copy(publicDir, api.context.distPath, {
6301
+ await import_shared51.fse.copy(publicDir, api.context.distPath, {
6171
6302
  // dereference symlinks
6172
6303
  dereference: true
6173
6304
  });
@@ -6281,7 +6412,6 @@ var init_manifest = __esm({
6281
6412
  name: "rsbuild:manifest",
6282
6413
  setup(api) {
6283
6414
  api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
6284
- const htmlPaths = api.getHTMLPaths();
6285
6415
  const {
6286
6416
  output: { manifest }
6287
6417
  } = api.getNormalizedConfig();
@@ -6290,6 +6420,7 @@ var init_manifest = __esm({
6290
6420
  }
6291
6421
  const fileName = typeof manifest === "string" ? manifest : "manifest.json";
6292
6422
  const { RspackManifestPlugin } = await import("../compiled/rspack-manifest-plugin/index.js");
6423
+ const htmlPaths = api.getHTMLPaths();
6293
6424
  chain.plugin(CHAIN_ID3.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
6294
6425
  {
6295
6426
  fileName,
@@ -6334,18 +6465,18 @@ function pluginModuleFederation() {
6334
6465
  chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
6335
6466
  }
6336
6467
  const publicPath = chain.output.get("publicPath");
6337
- if (publicPath === import_shared53.DEFAULT_ASSET_PREFIX) {
6468
+ if (publicPath === import_shared52.DEFAULT_ASSET_PREFIX) {
6338
6469
  chain.output.set("publicPath", "auto");
6339
6470
  }
6340
6471
  });
6341
6472
  }
6342
6473
  };
6343
6474
  }
6344
- var import_shared53, import_core8, PatchSplitChunksPlugin;
6475
+ var import_shared52, import_core8, PatchSplitChunksPlugin;
6345
6476
  var init_moduleFederation = __esm({
6346
6477
  "src/plugins/moduleFederation.ts"() {
6347
6478
  "use strict";
6348
- import_shared53 = require("@rsbuild/shared");
6479
+ import_shared52 = require("@rsbuild/shared");
6349
6480
  import_core8 = require("@rspack/core");
6350
6481
  PatchSplitChunksPlugin = class {
6351
6482
  constructor(name) {
@@ -6413,14 +6544,14 @@ __export(rspackProfile_exports, {
6413
6544
  pluginRspackProfile: () => pluginRspackProfile,
6414
6545
  stopProfiler: () => stopProfiler
6415
6546
  });
6416
- var import_node_inspector, import_node_path27, import_shared54, import_shared55, import_core9, stopProfiler, pluginRspackProfile;
6547
+ var import_node_inspector, import_node_path27, import_shared53, import_shared54, import_core9, stopProfiler, pluginRspackProfile;
6417
6548
  var init_rspackProfile = __esm({
6418
6549
  "src/plugins/rspackProfile.ts"() {
6419
6550
  "use strict";
6420
6551
  import_node_inspector = __toESM(require("inspector"));
6421
6552
  import_node_path27 = __toESM(require("path"));
6553
+ import_shared53 = require("@rsbuild/shared");
6422
6554
  import_shared54 = require("@rsbuild/shared");
6423
- import_shared55 = require("@rsbuild/shared");
6424
6555
  import_core9 = require("@rspack/core");
6425
6556
  stopProfiler = (output, profileSession) => {
6426
6557
  if (!profileSession) {
@@ -6428,10 +6559,10 @@ var init_rspackProfile = __esm({
6428
6559
  }
6429
6560
  profileSession.post("Profiler.stop", (error, param) => {
6430
6561
  if (error) {
6431
- import_shared55.logger.error("Failed to generate JS CPU profile:", error);
6562
+ import_shared54.logger.error("Failed to generate JS CPU profile:", error);
6432
6563
  return;
6433
6564
  }
6434
- import_shared54.fse.writeFileSync(output, JSON.stringify(param.profile));
6565
+ import_shared53.fse.writeFileSync(output, JSON.stringify(param.profile));
6435
6566
  });
6436
6567
  };
6437
6568
  pluginRspackProfile = () => ({
@@ -6457,7 +6588,7 @@ var init_rspackProfile = __esm({
6457
6588
  const cpuProfilePath = import_node_path27.default.join(profileDir, "jscpuprofile.json");
6458
6589
  const loggingFilePath = import_node_path27.default.join(profileDir, "logging.json");
6459
6590
  const onStart = () => {
6460
- import_shared54.fse.ensureDirSync(profileDir);
6591
+ import_shared53.fse.ensureDirSync(profileDir);
6461
6592
  if (enableProfileTrace) {
6462
6593
  import_core9.rspack.experimental_registerGlobalTrace(
6463
6594
  "trace",
@@ -6481,7 +6612,7 @@ var init_rspackProfile = __esm({
6481
6612
  logging: "verbose",
6482
6613
  loggingTrace: true
6483
6614
  });
6484
- import_shared54.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
6615
+ import_shared53.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
6485
6616
  }
6486
6617
  });
6487
6618
  api.onExit(() => {
@@ -6489,7 +6620,7 @@ var init_rspackProfile = __esm({
6489
6620
  import_core9.rspack.experimental_cleanupGlobalTrace();
6490
6621
  }
6491
6622
  stopProfiler(cpuProfilePath, profileSession);
6492
- import_shared55.logger.info(`Saved Rspack profile file to ${profileDir}`);
6623
+ import_shared54.logger.info(`Saved Rspack profile file to ${profileDir}`);
6493
6624
  });
6494
6625
  }
6495
6626
  });
@@ -6501,11 +6632,11 @@ var lazyCompilation_exports = {};
6501
6632
  __export(lazyCompilation_exports, {
6502
6633
  pluginLazyCompilation: () => pluginLazyCompilation
6503
6634
  });
6504
- var import_shared56, pluginLazyCompilation;
6635
+ var import_shared55, pluginLazyCompilation;
6505
6636
  var init_lazyCompilation = __esm({
6506
6637
  "src/plugins/lazyCompilation.ts"() {
6507
6638
  "use strict";
6508
- import_shared56 = require("@rsbuild/shared");
6639
+ import_shared55 = require("@rsbuild/shared");
6509
6640
  pluginLazyCompilation = () => ({
6510
6641
  name: "rsbuild:lazy-compilation",
6511
6642
  setup(api) {
@@ -6518,12 +6649,10 @@ var init_lazyCompilation = __esm({
6518
6649
  if (!options) {
6519
6650
  return;
6520
6651
  }
6521
- const clientRegExp = /[\\/]core[\\/]dist[\\/]client[\\/]/;
6522
6652
  const cssRegExp = /\.(?:css|less|sass|scss|styl|stylus)$/;
6523
6653
  const isExcludedModule = (name) => {
6524
6654
  return (
6525
- // alway include Rsbuild client code, such as HMR
6526
- clientRegExp.test(name) || // exclude CSS files because Rspack does not support it yet
6655
+ // exclude CSS files because Rspack does not support it yet
6527
6656
  // TODO: remove this after Rspack supporting it
6528
6657
  cssRegExp.test(name)
6529
6658
  );
@@ -6553,7 +6682,7 @@ var init_lazyCompilation = __esm({
6553
6682
  if (!name || isExcludedModule(name)) {
6554
6683
  return false;
6555
6684
  }
6556
- if ((0, import_shared56.isRegExp)(test)) {
6685
+ if ((0, import_shared55.isRegExp)(test)) {
6557
6686
  return name ? test.test(name) : false;
6558
6687
  }
6559
6688
  return test(module2);
@@ -6575,18 +6704,18 @@ var sri_exports = {};
6575
6704
  __export(sri_exports, {
6576
6705
  pluginSri: () => pluginSri
6577
6706
  });
6578
- var import_node_crypto2, import_shared57, getAssetName, pluginSri;
6707
+ var import_node_crypto2, import_shared56, getAssetName, pluginSri;
6579
6708
  var init_sri = __esm({
6580
6709
  "src/plugins/sri.ts"() {
6581
6710
  "use strict";
6582
6711
  import_node_crypto2 = __toESM(require("crypto"));
6583
- import_shared57 = require("@rsbuild/shared");
6712
+ import_shared56 = require("@rsbuild/shared");
6584
6713
  init_constants();
6585
6714
  getAssetName = (url2, assetPrefix) => {
6586
6715
  if (url2.startsWith(assetPrefix)) {
6587
- return (0, import_shared57.removeLeadingSlash)(url2.replace(assetPrefix, ""));
6716
+ return (0, import_shared56.removeLeadingSlash)(url2.replace(assetPrefix, ""));
6588
6717
  }
6589
- return (0, import_shared57.removeLeadingSlash)(url2);
6718
+ return (0, import_shared56.removeLeadingSlash)(url2);
6590
6719
  };
6591
6720
  pluginSri = () => ({
6592
6721
  name: "rsbuild:sri",
@@ -6595,7 +6724,7 @@ var init_sri = __esm({
6595
6724
  const getAlgorithm = () => {
6596
6725
  const config = api.getNormalizedConfig();
6597
6726
  const { sri } = config.security;
6598
- const enable = sri.enable === "auto" ? (0, import_shared57.isProd)() : sri.enable;
6727
+ const enable = sri.enable === "auto" ? (0, import_shared56.isProd)() : sri.enable;
6599
6728
  if (!enable) {
6600
6729
  return null;
6601
6730
  }
@@ -6662,7 +6791,7 @@ var init_sri = __esm({
6662
6791
  `integrity="${integrity}"`
6663
6792
  );
6664
6793
  } else {
6665
- import_shared57.logger.debug(
6794
+ import_shared56.logger.debug(
6666
6795
  `[rsbuild:sri] failed to generate integrity for ${assetName}.`
6667
6796
  );
6668
6797
  replacedHtml = replacedHtml.replace(
@@ -6715,7 +6844,7 @@ var init_sri = __esm({
6715
6844
  }
6716
6845
  api.modifyBundlerChain((chain, { target }) => {
6717
6846
  const config = api.getNormalizedConfig();
6718
- if ((0, import_shared57.isHtmlDisabled)(config, target)) {
6847
+ if ((0, import_shared56.isHtmlDisabled)(config, target)) {
6719
6848
  return;
6720
6849
  }
6721
6850
  const algorithm = getAlgorithm();
@@ -6734,11 +6863,11 @@ var nonce_exports = {};
6734
6863
  __export(nonce_exports, {
6735
6864
  pluginNonce: () => pluginNonce
6736
6865
  });
6737
- var import_shared58, pluginNonce;
6866
+ var import_shared57, pluginNonce;
6738
6867
  var init_nonce = __esm({
6739
6868
  "src/plugins/nonce.ts"() {
6740
6869
  "use strict";
6741
- import_shared58 = require("@rsbuild/shared");
6870
+ import_shared57 = require("@rsbuild/shared");
6742
6871
  pluginNonce = () => ({
6743
6872
  name: "rsbuild:nonce",
6744
6873
  setup(api) {
@@ -6747,7 +6876,7 @@ var init_nonce = __esm({
6747
6876
  if (!nonce) {
6748
6877
  return;
6749
6878
  }
6750
- (0, import_shared58.applyToCompiler)(compiler, (compiler2) => {
6879
+ (0, import_shared57.applyToCompiler)(compiler, (compiler2) => {
6751
6880
  const { plugins } = compiler2.options;
6752
6881
  const hasHTML = plugins.some(
6753
6882
  (plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
@@ -6755,7 +6884,7 @@ var init_nonce = __esm({
6755
6884
  if (!hasHTML) {
6756
6885
  return;
6757
6886
  }
6758
- const injectCode = (0, import_shared58.createVirtualModule)(
6887
+ const injectCode = (0, import_shared57.createVirtualModule)(
6759
6888
  `__webpack_nonce__ = "${nonce}";`
6760
6889
  );
6761
6890
  new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
@@ -6813,7 +6942,7 @@ async function applyDefaultPlugins(pluginManager, context) {
6813
6942
  const { pluginSwc: pluginSwc2 } = await Promise.resolve().then(() => (init_swc(), swc_exports));
6814
6943
  const { pluginExternals: pluginExternals2 } = await Promise.resolve().then(() => (init_externals(), externals_exports));
6815
6944
  const { pluginSplitChunks: pluginSplitChunks2 } = await Promise.resolve().then(() => (init_splitChunks(), splitChunks_exports));
6816
- const { pluginStartUrl: pluginStartUrl2 } = await Promise.resolve().then(() => (init_startUrl(), startUrl_exports));
6945
+ const { pluginOpen: pluginOpen2 } = await Promise.resolve().then(() => (init_open(), open_exports));
6817
6946
  const { pluginInlineChunk: pluginInlineChunk2 } = await Promise.resolve().then(() => (init_inlineChunk(), inlineChunk_exports));
6818
6947
  const { pluginBundleAnalyzer: pluginBundleAnalyzer2 } = await Promise.resolve().then(() => (init_bundleAnalyzer(), bundleAnalyzer_exports));
6819
6948
  const { pluginRsdoctor: pluginRsdoctor2 } = await Promise.resolve().then(() => (init_rsdoctor(), rsdoctor_exports));
@@ -6851,7 +6980,7 @@ async function applyDefaultPlugins(pluginManager, context) {
6851
6980
  pluginSwc2(),
6852
6981
  pluginExternals2(),
6853
6982
  pluginSplitChunks2(),
6854
- pluginStartUrl2(),
6983
+ pluginOpen2(),
6855
6984
  pluginInlineChunk2(),
6856
6985
  pluginBundleAnalyzer2(),
6857
6986
  pluginRsdoctor2(),
@@ -6881,9 +7010,9 @@ async function createRsbuild(options = {}) {
6881
7010
  );
6882
7011
  const pluginAPI = getPluginAPI({ context, pluginManager });
6883
7012
  context.pluginAPI = pluginAPI;
6884
- (0, import_shared59.debug)("add default plugins");
7013
+ (0, import_shared58.debug)("add default plugins");
6885
7014
  await applyDefaultPlugins(pluginManager, context);
6886
- (0, import_shared59.debug)("add default plugins done");
7015
+ (0, import_shared58.debug)("add default plugins done");
6887
7016
  const provider = rsbuildConfig.provider || await getRspackProvider();
6888
7017
  const providerInstance = await provider({
6889
7018
  context,
@@ -6892,13 +7021,13 @@ async function createRsbuild(options = {}) {
6892
7021
  setCssExtractPlugin
6893
7022
  });
6894
7023
  const rsbuild = {
6895
- ...(0, import_shared59.pick)(pluginManager, [
7024
+ ...(0, import_shared58.pick)(pluginManager, [
6896
7025
  "addPlugins",
6897
7026
  "getPlugins",
6898
7027
  "removePlugins",
6899
7028
  "isPluginExists"
6900
7029
  ]),
6901
- ...(0, import_shared59.pick)(pluginAPI, [
7030
+ ...(0, import_shared58.pick)(pluginAPI, [
6902
7031
  "onBeforeBuild",
6903
7032
  "onBeforeCreateCompiler",
6904
7033
  "onBeforeStartDevServer",
@@ -6914,7 +7043,7 @@ async function createRsbuild(options = {}) {
6914
7043
  "getRsbuildConfig",
6915
7044
  "getNormalizedConfig"
6916
7045
  ]),
6917
- ...(0, import_shared59.pick)(providerInstance, [
7046
+ ...(0, import_shared58.pick)(providerInstance, [
6918
7047
  "build",
6919
7048
  "preview",
6920
7049
  "initConfigs",
@@ -6931,11 +7060,11 @@ async function createRsbuild(options = {}) {
6931
7060
  }
6932
7061
  return rsbuild;
6933
7062
  }
6934
- var import_shared59, getRspackProvider, pickRsbuildConfig;
7063
+ var import_shared58, getRspackProvider, pickRsbuildConfig;
6935
7064
  var init_createRsbuild = __esm({
6936
7065
  "src/createRsbuild.ts"() {
6937
7066
  "use strict";
6938
- import_shared59 = require("@rsbuild/shared");
7067
+ import_shared58 = require("@rsbuild/shared");
6939
7068
  init_createContext();
6940
7069
  init_initPlugins();
6941
7070
  init_pluginHelper();
@@ -6957,7 +7086,7 @@ var init_createRsbuild = __esm({
6957
7086
  "moduleFederation",
6958
7087
  "_privateMeta"
6959
7088
  ];
6960
- return (0, import_shared59.pick)(rsbuildConfig, keys);
7089
+ return (0, import_shared58.pick)(rsbuildConfig, keys);
6961
7090
  };
6962
7091
  }
6963
7092
  });
@@ -6976,7 +7105,7 @@ async function init({
6976
7105
  cwd: root,
6977
7106
  mode: cliOptions?.envMode
6978
7107
  });
6979
- if ((0, import_shared60.isDev)()) {
7108
+ if ((0, import_shared59.isDev)()) {
6980
7109
  onBeforeRestartServer(envs.cleanup);
6981
7110
  }
6982
7111
  const { content: config, filePath: configFilePath } = await loadConfig({
@@ -6998,9 +7127,9 @@ async function init({
6998
7127
  ...envs.publicVars,
6999
7128
  ...config.source.define
7000
7129
  };
7001
- if (commonOpts.open && !config.dev?.startUrl) {
7002
- config.dev ||= {};
7003
- config.dev.startUrl = commonOpts.open;
7130
+ if (commonOpts.open && !config.server?.open) {
7131
+ config.server ||= {};
7132
+ config.server.open = commonOpts.open;
7004
7133
  }
7005
7134
  if (commonOpts.host) {
7006
7135
  config.server ||= {};
@@ -7016,17 +7145,17 @@ async function init({
7016
7145
  });
7017
7146
  } catch (err) {
7018
7147
  if (isRestart) {
7019
- import_shared60.logger.error(err);
7148
+ import_shared59.logger.error(err);
7020
7149
  } else {
7021
7150
  throw err;
7022
7151
  }
7023
7152
  }
7024
7153
  }
7025
- var import_shared60, commonOpts;
7154
+ var import_shared59, commonOpts;
7026
7155
  var init_init = __esm({
7027
7156
  "src/cli/init.ts"() {
7028
7157
  "use strict";
7029
- import_shared60 = require("@rsbuild/shared");
7158
+ import_shared59 = require("@rsbuild/shared");
7030
7159
  init_config();
7031
7160
  init_loadEnv();
7032
7161
  init_restart();
@@ -7044,7 +7173,7 @@ __export(src_exports, {
7044
7173
  defineConfig: () => defineConfig,
7045
7174
  loadConfig: () => loadConfig,
7046
7175
  loadEnv: () => loadEnv,
7047
- logger: () => import_shared63.logger,
7176
+ logger: () => import_shared62.logger,
7048
7177
  mergeRsbuildConfig: () => mergeRsbuildConfig,
7049
7178
  rspack: () => import_core10.rspack,
7050
7179
  version: () => version
@@ -7067,16 +7196,18 @@ __export(internal_exports, {
7067
7196
  initHooks: () => initHooks,
7068
7197
  initPlugins: () => initPlugins,
7069
7198
  initRsbuildConfig: () => initRsbuildConfig,
7199
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
7070
7200
  prepareCli: () => prepareCli,
7071
7201
  runCli: () => runCli,
7072
7202
  setHTMLPlugin: () => setHTMLPlugin,
7073
- startProdServer: () => startProdServer
7203
+ startProdServer: () => startProdServer,
7204
+ stringifyConfig: () => stringifyConfig
7074
7205
  });
7075
7206
 
7076
7207
  // src/cli/commands.ts
7077
7208
  var import_node_fs5 = require("fs");
7078
7209
  var import_node_path28 = require("path");
7079
- var import_shared61 = require("@rsbuild/shared");
7210
+ var import_shared60 = require("@rsbuild/shared");
7080
7211
  var import_commander = require("../compiled/commander/index.js");
7081
7212
  init_helpers();
7082
7213
  init_init();
@@ -7093,7 +7224,7 @@ var applyServerOptions = (command) => {
7093
7224
  command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
7094
7225
  };
7095
7226
  function runCli() {
7096
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.3");
7227
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.5");
7097
7228
  const devCommand = import_commander.program.command("dev");
7098
7229
  const buildCommand = import_commander.program.command("build");
7099
7230
  const previewCommand = import_commander.program.command("preview");
@@ -7107,8 +7238,8 @@ function runCli() {
7107
7238
  const rsbuild = await init({ cliOptions: options });
7108
7239
  await rsbuild?.startDevServer();
7109
7240
  } catch (err) {
7110
- import_shared61.logger.error("Failed to start dev server.");
7111
- import_shared61.logger.error(err);
7241
+ import_shared60.logger.error("Failed to start dev server.");
7242
+ import_shared60.logger.error(err);
7112
7243
  process.exit(1);
7113
7244
  }
7114
7245
  });
@@ -7119,8 +7250,8 @@ function runCli() {
7119
7250
  watch: options.watch
7120
7251
  });
7121
7252
  } catch (err) {
7122
- import_shared61.logger.error("Failed to build.");
7123
- import_shared61.logger.error(err);
7253
+ import_shared60.logger.error("Failed to build.");
7254
+ import_shared60.logger.error(err);
7124
7255
  process.exit(1);
7125
7256
  }
7126
7257
  });
@@ -7131,14 +7262,14 @@ function runCli() {
7131
7262
  const { distPath } = rsbuild.context;
7132
7263
  if (!(0, import_node_fs5.existsSync)(distPath)) {
7133
7264
  throw new Error(
7134
- `The output directory ${import_shared61.color.yellow(
7265
+ `The output directory ${import_shared60.color.yellow(
7135
7266
  distPath
7136
7267
  )} does not exist, please build the project before previewing.`
7137
7268
  );
7138
7269
  }
7139
7270
  if (isEmptyDir(distPath)) {
7140
7271
  throw new Error(
7141
- `The output directory ${import_shared61.color.yellow(
7272
+ `The output directory ${import_shared60.color.yellow(
7142
7273
  distPath
7143
7274
  )} is empty, please build the project before previewing.`
7144
7275
  );
@@ -7146,8 +7277,8 @@ function runCli() {
7146
7277
  }
7147
7278
  await rsbuild?.preview();
7148
7279
  } catch (err) {
7149
- import_shared61.logger.error("Failed to start preview server.");
7150
- import_shared61.logger.error(err);
7280
+ import_shared60.logger.error("Failed to start preview server.");
7281
+ import_shared60.logger.error(err);
7151
7282
  process.exit(1);
7152
7283
  }
7153
7284
  });
@@ -7161,8 +7292,8 @@ function runCli() {
7161
7292
  writeToDisk: true
7162
7293
  });
7163
7294
  } catch (err) {
7164
- import_shared61.logger.error("Failed to inspect config.");
7165
- import_shared61.logger.error(err);
7295
+ import_shared60.logger.error("Failed to inspect config.");
7296
+ import_shared60.logger.error(err);
7166
7297
  process.exit(1);
7167
7298
  }
7168
7299
  });
@@ -7170,7 +7301,7 @@ function runCli() {
7170
7301
  }
7171
7302
 
7172
7303
  // src/cli/prepare.ts
7173
- var import_shared62 = require("@rsbuild/shared");
7304
+ var import_shared61 = require("@rsbuild/shared");
7174
7305
  function initNodeEnv() {
7175
7306
  if (!process.env.NODE_ENV) {
7176
7307
  const command = process.argv[2];
@@ -7183,7 +7314,7 @@ function prepareCli() {
7183
7314
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7184
7315
  console.log();
7185
7316
  }
7186
- import_shared62.logger.greet(` ${`Rsbuild v${"0.7.3"}`}
7317
+ import_shared61.logger.greet(` ${`Rsbuild v${"0.7.5"}`}
7187
7318
  `);
7188
7319
  }
7189
7320
 
@@ -7191,6 +7322,7 @@ function prepareCli() {
7191
7322
  init_pluginManager();
7192
7323
  init_initHooks();
7193
7324
  init_initConfigs();
7325
+ init_config();
7194
7326
  init_pluginHelper();
7195
7327
  init_helpers();
7196
7328
  init_rspackConfig();
@@ -7206,10 +7338,10 @@ init_prodServer();
7206
7338
  init_loadEnv();
7207
7339
  init_createRsbuild();
7208
7340
  init_config();
7209
- var import_shared63 = require("@rsbuild/shared");
7341
+ var import_shared62 = require("@rsbuild/shared");
7210
7342
  init_mergeConfig();
7211
7343
  init_constants();
7212
- var version = "0.7.3";
7344
+ var version = "0.7.5";
7213
7345
  // Annotate the CommonJS export names for ESM import in node:
7214
7346
  0 && (module.exports = {
7215
7347
  PLUGIN_CSS_NAME,