@rsbuild/core 0.7.3 → 0.7.4

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.js CHANGED
@@ -23,12 +23,12 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
 
26
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.51.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
26
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
27
27
  import { fileURLToPath } from "url";
28
28
  import path from "path";
29
29
  var getFilename, getDirname, __dirname, __filename;
30
30
  var init_esm = __esm({
31
- "../../node_modules/.pnpm/@modern-js+module-tools@2.51.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
31
+ "../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
32
32
  "use strict";
33
33
  getFilename = () => fileURLToPath(import.meta.url);
34
34
  getDirname = () => path.dirname(getFilename());
@@ -118,19 +118,53 @@ var init_format = __esm({
118
118
 
119
119
  // src/constants.ts
120
120
  import { join } from "path";
121
- var PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HTML_REGEX, CSS_REGEX;
121
+ var 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;
122
122
  var init_constants = __esm({
123
123
  "src/constants.ts"() {
124
124
  "use strict";
125
125
  init_esm();
126
- PLUGIN_SWC_NAME = "rsbuild:swc";
127
- PLUGIN_CSS_NAME = "rsbuild:css";
126
+ ROOT_DIST_DIR = "dist";
127
+ HTML_DIST_DIR = "/";
128
+ SERVER_DIST_DIR = "server";
129
+ SERVICE_WORKER_DIST_DIR = "worker";
130
+ JS_DIST_DIR = "static/js";
131
+ CSS_DIST_DIR = "static/css";
132
+ SVG_DIST_DIR = "static/svg";
133
+ FONT_DIST_DIR = "static/font";
134
+ WASM_DIST_DIR = "static/wasm";
135
+ IMAGE_DIST_DIR = "static/image";
136
+ MEDIA_DIST_DIR = "static/media";
128
137
  LOADER_PATH = join(__dirname);
129
138
  STATIC_PATH = join(__dirname, "../static");
130
139
  COMPILED_PATH = join(__dirname, "../compiled");
131
140
  TS_CONFIG_FILE = "tsconfig.json";
141
+ DEFAULT_PORT = 3e3;
142
+ DEFAULT_DATA_URL_SIZE = 4096;
143
+ DEFAULT_MOUNT_ID = "root";
144
+ DEFAULT_DEV_HOST = "0.0.0.0";
132
145
  HTML_REGEX = /\.html$/;
133
146
  CSS_REGEX = /\.css$/;
147
+ PLUGIN_SWC_NAME = "rsbuild:swc";
148
+ PLUGIN_CSS_NAME = "rsbuild:css";
149
+ FONT_EXTENSIONS = ["woff", "woff2", "eot", "ttf", "otf", "ttc"];
150
+ IMAGE_EXTENSIONS = [
151
+ "png",
152
+ "jpg",
153
+ "jpeg",
154
+ "pjpeg",
155
+ "pjp",
156
+ "gif",
157
+ "bmp",
158
+ "webp",
159
+ "ico",
160
+ "apng",
161
+ "avif",
162
+ "tif",
163
+ "tiff",
164
+ "jfif"
165
+ ];
166
+ VIDEO_EXTENSIONS = ["mp4", "webm", "ogg", "mov"];
167
+ AUDIO_EXTENSIONS = ["mp3", "wav", "flac", "aac", "m4a", "opus"];
134
168
  }
135
169
  });
136
170
 
@@ -371,6 +405,7 @@ var init_mergeConfig = __esm({
371
405
  "output.cssModules.auto",
372
406
  "output.targets",
373
407
  "output.emitAssets",
408
+ "server.open",
374
409
  "server.printUrls",
375
410
  "dev.startUrl",
376
411
  "provider"
@@ -459,27 +494,15 @@ var init_restart = __esm({
459
494
  import fs from "fs";
460
495
  import { isAbsolute, join as join2 } from "path";
461
496
  import {
462
- CSS_DIST_DIR,
463
497
  DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX2,
464
- DEFAULT_DATA_URL_SIZE,
465
- DEFAULT_DEV_HOST,
466
- DEFAULT_MOUNT_ID,
467
- DEFAULT_PORT,
468
- FONT_DIST_DIR,
469
- HTML_DIST_DIR,
470
- IMAGE_DIST_DIR,
471
- JS_DIST_DIR,
472
- MEDIA_DIST_DIR,
473
- ROOT_DIST_DIR,
474
- SERVER_DIST_DIR,
475
- SERVICE_WORKER_DIST_DIR,
476
- SVG_DIST_DIR,
477
- WASM_DIST_DIR,
498
+ RspackChain,
478
499
  color as color3,
479
500
  debounce,
501
+ fse as fse2,
480
502
  getNodeEnv,
481
503
  isObject,
482
- logger as logger2
504
+ logger as logger2,
505
+ upperFirst
483
506
  } from "@rsbuild/shared";
484
507
  function getDefaultEntry(root) {
485
508
  const files = [
@@ -583,6 +606,55 @@ async function loadConfig({
583
606
  throw err;
584
607
  }
585
608
  }
609
+ async function outputInspectConfigFiles({
610
+ rsbuildConfig,
611
+ rawRsbuildConfig,
612
+ bundlerConfigs,
613
+ inspectOptions,
614
+ configType
615
+ }) {
616
+ const { outputPath } = inspectOptions;
617
+ const files = [
618
+ {
619
+ path: join2(outputPath, "rsbuild.config.mjs"),
620
+ label: "Rsbuild Config",
621
+ content: rawRsbuildConfig
622
+ },
623
+ ...bundlerConfigs.map((content, index) => {
624
+ const suffix = rsbuildConfig.output.targets[index];
625
+ const outputFile = `${configType}.config.${suffix}.mjs`;
626
+ let outputFilePath = join2(outputPath, outputFile);
627
+ if (fse2.existsSync(outputFilePath)) {
628
+ outputFilePath = outputFilePath.replace(/\.mjs$/, `.${Date.now()}.mjs`);
629
+ }
630
+ return {
631
+ path: outputFilePath,
632
+ label: `${upperFirst(configType)} Config (${suffix})`,
633
+ content
634
+ };
635
+ })
636
+ ];
637
+ await Promise.all(
638
+ files.map(
639
+ (item) => fse2.outputFile(item.path, `export default ${item.content}`)
640
+ )
641
+ );
642
+ const fileInfos = files.map(
643
+ (item) => ` - ${color3.bold(color3.yellow(item.label))}: ${color3.underline(
644
+ item.path
645
+ )}`
646
+ ).join("\n");
647
+ logger2.success(
648
+ `Inspect config succeed, open following files to view the content:
649
+
650
+ ${fileInfos}
651
+ `
652
+ );
653
+ }
654
+ async function stringifyConfig(config, verbose) {
655
+ const stringify = RspackChain.toString;
656
+ return stringify(config, { verbose });
657
+ }
586
658
  var getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath;
587
659
  var init_config = __esm({
588
660
  "src/config.ts"() {
@@ -604,6 +676,7 @@ var init_config = __esm({
604
676
  getDefaultServerConfig = () => ({
605
677
  port: DEFAULT_PORT,
606
678
  host: DEFAULT_DEV_HOST,
679
+ open: false,
607
680
  htmlFallback: "index",
608
681
  compress: true,
609
682
  printUrls: true,
@@ -969,7 +1042,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
969
1042
  return {
970
1043
  entry: getEntryObject(config, "web"),
971
1044
  targets: config.output?.targets || [],
972
- version: "0.7.3",
1045
+ version: "0.7.4",
973
1046
  rootPath,
974
1047
  distPath,
975
1048
  cachePath,
@@ -1371,9 +1444,7 @@ __export(inspectConfig_exports, {
1371
1444
  import { isAbsolute as isAbsolute3, join as join6 } from "path";
1372
1445
  import {
1373
1446
  getNodeEnv as getNodeEnv3,
1374
- outputInspectConfigFiles,
1375
- setNodeEnv,
1376
- stringifyConfig
1447
+ setNodeEnv
1377
1448
  } from "@rsbuild/shared";
1378
1449
  async function inspectConfig({
1379
1450
  context,
@@ -1434,6 +1505,7 @@ var init_inspectConfig = __esm({
1434
1505
  "src/provider/inspectConfig.ts"() {
1435
1506
  "use strict";
1436
1507
  init_esm();
1508
+ init_config();
1437
1509
  init_initConfigs();
1438
1510
  }
1439
1511
  });
@@ -2191,8 +2263,6 @@ var init_getDevMiddlewares = __esm({
2191
2263
  import net from "net";
2192
2264
  import os from "os";
2193
2265
  import {
2194
- DEFAULT_DEV_HOST as DEFAULT_DEV_HOST2,
2195
- DEFAULT_PORT as DEFAULT_PORT2,
2196
2266
  color as color8,
2197
2267
  deepmerge,
2198
2268
  isFunction as isFunction4,
@@ -2268,6 +2338,7 @@ var init_helper = __esm({
2268
2338
  "src/server/helper.ts"() {
2269
2339
  "use strict";
2270
2340
  init_esm();
2341
+ init_constants();
2271
2342
  formatPrefix = (prefix) => {
2272
2343
  if (!prefix) {
2273
2344
  return "/";
@@ -2342,10 +2413,10 @@ var init_helper = __esm({
2342
2413
  config,
2343
2414
  getPortSilently
2344
2415
  }) => {
2345
- const host = config.server.host || DEFAULT_DEV_HOST2;
2416
+ const host = config.server.host || DEFAULT_DEV_HOST;
2346
2417
  const port = await getPort({
2347
2418
  host,
2348
- port: config.server.port || DEFAULT_PORT2,
2419
+ port: config.server.port || DEFAULT_PORT,
2349
2420
  strictPort: config.server.strictPort || false,
2350
2421
  silent: getPortSilently
2351
2422
  });
@@ -2419,7 +2490,7 @@ var init_helper = __esm({
2419
2490
  port,
2420
2491
  host
2421
2492
  }) => {
2422
- if (host && host !== DEFAULT_DEV_HOST2) {
2493
+ if (host && host !== DEFAULT_DEV_HOST) {
2423
2494
  return [
2424
2495
  {
2425
2496
  label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
@@ -2802,7 +2873,6 @@ __export(devServer_exports, {
2802
2873
  });
2803
2874
  import fs3 from "fs";
2804
2875
  import {
2805
- ROOT_DIST_DIR as ROOT_DIST_DIR2,
2806
2876
  debug as debug6,
2807
2877
  getNodeEnv as getNodeEnv5,
2808
2878
  getPublicPathFromCompiler,
@@ -2894,7 +2964,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2894
2964
  dev: devConfig,
2895
2965
  server: serverConfig,
2896
2966
  output: {
2897
- distPath: config.output.distPath.root || ROOT_DIST_DIR2
2967
+ distPath: config.output.distPath.root || ROOT_DIST_DIR
2898
2968
  },
2899
2969
  outputFileSystem
2900
2970
  });
@@ -2967,6 +3037,7 @@ var init_devServer = __esm({
2967
3037
  "src/server/devServer.ts"() {
2968
3038
  "use strict";
2969
3039
  init_esm();
3040
+ init_constants();
2970
3041
  init_getDevMiddlewares();
2971
3042
  init_helper();
2972
3043
  init_httpServer();
@@ -2984,7 +3055,6 @@ __export(prodServer_exports, {
2984
3055
  });
2985
3056
  import { join as join8 } from "path";
2986
3057
  import {
2987
- ROOT_DIST_DIR as ROOT_DIST_DIR3,
2988
3058
  getNodeEnv as getNodeEnv6,
2989
3059
  isDebug as isDebug4,
2990
3060
  setNodeEnv as setNodeEnv3
@@ -3004,7 +3074,7 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
3004
3074
  {
3005
3075
  pwd: context.rootPath,
3006
3076
  output: {
3007
- path: config.output.distPath.root || ROOT_DIST_DIR3,
3077
+ path: config.output.distPath.root || ROOT_DIST_DIR,
3008
3078
  assetPrefix: config.output.assetPrefix
3009
3079
  },
3010
3080
  serverConfig
@@ -3064,6 +3134,7 @@ var init_prodServer = __esm({
3064
3134
  "src/server/prodServer.ts"() {
3065
3135
  "use strict";
3066
3136
  init_esm();
3137
+ init_constants();
3067
3138
  init_helper();
3068
3139
  init_httpServer();
3069
3140
  init_middlewares();
@@ -3372,17 +3443,17 @@ __export(cache_exports, {
3372
3443
  });
3373
3444
  import crypto from "crypto";
3374
3445
  import { isAbsolute as isAbsolute5, join as join9 } from "path";
3375
- import { fse as fse2 } from "@rsbuild/shared";
3446
+ import { fse as fse3 } from "@rsbuild/shared";
3376
3447
  async function validateCache(cacheDirectory, buildDependencies) {
3377
3448
  const configFile = join9(cacheDirectory, "buildDependencies.json");
3378
3449
  if (await isFileExists(configFile)) {
3379
- const prevBuildDependencies = await fse2.readJSON(configFile);
3450
+ const prevBuildDependencies = await fse3.readJSON(configFile);
3380
3451
  if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
3381
3452
  return;
3382
3453
  }
3383
- await fse2.remove(cacheDirectory);
3454
+ await fse3.remove(cacheDirectory);
3384
3455
  }
3385
- await fse2.outputJSON(configFile, buildDependencies);
3456
+ await fse3.outputJSON(configFile, buildDependencies);
3386
3457
  }
3387
3458
  function getDigestHash(digest) {
3388
3459
  const fsHash = crypto.createHash("md5");
@@ -3744,8 +3815,6 @@ __export(output_exports, {
3744
3815
  import { posix } from "path";
3745
3816
  import {
3746
3817
  DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX3,
3747
- DEFAULT_DEV_HOST as DEFAULT_DEV_HOST3,
3748
- DEFAULT_PORT as DEFAULT_PORT3,
3749
3818
  getDistPath as getDistPath3,
3750
3819
  getFilename as getFilename2
3751
3820
  } from "@rsbuild/shared";
@@ -3765,9 +3834,9 @@ function getPublicPath({
3765
3834
  publicPath = dev.assetPrefix;
3766
3835
  } else if (dev.assetPrefix === true) {
3767
3836
  const protocol = context.devServer?.https ? "https" : "http";
3768
- const hostname = context.devServer?.hostname || DEFAULT_DEV_HOST3;
3769
- const port = context.devServer?.port || DEFAULT_PORT3;
3770
- if (hostname === DEFAULT_DEV_HOST3) {
3837
+ const hostname = context.devServer?.hostname || DEFAULT_DEV_HOST;
3838
+ const port = context.devServer?.port || DEFAULT_PORT;
3839
+ if (hostname === DEFAULT_DEV_HOST) {
3771
3840
  const localHostname = "localhost";
3772
3841
  publicPath = `${protocol}://${localHostname}:${port}/`;
3773
3842
  } else {
@@ -3781,6 +3850,7 @@ var init_output = __esm({
3781
3850
  "src/plugins/output.ts"() {
3782
3851
  "use strict";
3783
3852
  init_esm();
3853
+ init_constants();
3784
3854
  init_helpers();
3785
3855
  init_pluginHelper();
3786
3856
  init_css();
@@ -3798,7 +3868,18 @@ var init_output = __esm({
3798
3868
  const jsPath = getDistPath3(config, "js");
3799
3869
  const jsAsyncPath = getDistPath3(config, "jsAsync");
3800
3870
  const jsFilename = getFilename2(config, "js", isProd5);
3801
- chain.output.path(api.context.distPath).filename(posix.join(jsPath, jsFilename)).chunkFilename(posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3871
+ const isJsFilenameFn = typeof jsFilename === "function";
3872
+ chain.output.path(api.context.distPath).filename(
3873
+ isJsFilenameFn ? (...args) => {
3874
+ const name = jsFilename(...args);
3875
+ return posix.join(jsPath, name);
3876
+ } : posix.join(jsPath, jsFilename)
3877
+ ).chunkFilename(
3878
+ isJsFilenameFn ? (...args) => {
3879
+ const name = jsFilename(...args);
3880
+ return posix.join(jsAsyncPath, name);
3881
+ } : posix.join(jsAsyncPath, jsFilename)
3882
+ ).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3802
3883
  if (isServer) {
3803
3884
  const serverPath = getDistPath3(config, "server");
3804
3885
  chain.output.path(posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
@@ -3935,7 +4016,7 @@ __export(fileSize_exports, {
3935
4016
  pluginFileSize: () => pluginFileSize
3936
4017
  });
3937
4018
  import path7 from "path";
3938
- import { JS_REGEX, fse as fse3 } from "@rsbuild/shared";
4019
+ import { JS_REGEX, fse as fse4 } from "@rsbuild/shared";
3939
4020
  import { color as color9, logger as logger11 } from "@rsbuild/shared";
3940
4021
  async function printHeader(longestFileLength, longestLabelLength) {
3941
4022
  const longestLengths = [longestFileLength, longestLabelLength];
@@ -3956,7 +4037,7 @@ async function printFileSizes(config, stats, rootPath) {
3956
4037
  const { default: gzipSize } = await import("@rsbuild/shared/gzip-size");
3957
4038
  const formatAsset = (asset, distPath, distFolder) => {
3958
4039
  const fileName = asset.name.split("?")[0];
3959
- const contents = fse3.readFileSync(path7.join(distPath, fileName));
4040
+ const contents = fse4.readFileSync(path7.join(distPath, fileName));
3960
4041
  const size = contents.length;
3961
4042
  const gzippedSize = gzipSize.sync(contents);
3962
4043
  return {
@@ -4109,15 +4190,15 @@ __export(cleanOutput_exports, {
4109
4190
  pluginCleanOutput: () => pluginCleanOutput
4110
4191
  });
4111
4192
  import { sep } from "path";
4112
- import { color as color10, fse as fse4, logger as logger12 } from "@rsbuild/shared";
4193
+ import { color as color10, fse as fse5, logger as logger12 } from "@rsbuild/shared";
4113
4194
  var emptyDir, addTrailingSep, isStrictSubdir, pluginCleanOutput;
4114
4195
  var init_cleanOutput = __esm({
4115
4196
  "src/plugins/cleanOutput.ts"() {
4116
4197
  "use strict";
4117
4198
  init_esm();
4118
4199
  emptyDir = async (dir) => {
4119
- if (await fse4.pathExists(dir)) {
4120
- await fse4.emptyDir(dir);
4200
+ if (await fse5.pathExists(dir)) {
4201
+ await fse5.emptyDir(dir);
4121
4202
  }
4122
4203
  };
4123
4204
  addTrailingSep = (dir) => dir.endsWith(sep) ? dir : dir + sep;
@@ -4164,14 +4245,7 @@ __export(asset_exports, {
4164
4245
  pluginAsset: () => pluginAsset
4165
4246
  });
4166
4247
  import path8 from "path";
4167
- import {
4168
- AUDIO_EXTENSIONS,
4169
- FONT_EXTENSIONS,
4170
- IMAGE_EXTENSIONS,
4171
- VIDEO_EXTENSIONS,
4172
- getDistPath as getDistPath4,
4173
- getFilename as getFilename3
4174
- } from "@rsbuild/shared";
4248
+ import { getDistPath as getDistPath4, getFilename as getFilename3 } from "@rsbuild/shared";
4175
4249
  function getRegExpForExts(exts) {
4176
4250
  const matcher = exts.map((ext) => ext.trim()).map((ext) => ext.startsWith(".") ? ext.slice(1) : ext).join("|");
4177
4251
  return new RegExp(
@@ -4184,6 +4258,7 @@ var init_asset = __esm({
4184
4258
  "src/plugins/asset.ts"() {
4185
4259
  "use strict";
4186
4260
  init_esm();
4261
+ init_constants();
4187
4262
  chainStaticAssetRule = ({
4188
4263
  emit,
4189
4264
  rule,
@@ -4540,20 +4615,18 @@ var init_HtmlBasicPlugin = __esm({
4540
4615
  addTitleTag(headTags, data.plugin.options?.title);
4541
4616
  }
4542
4617
  addFavicon(headTags, favicon);
4543
- const result = await this.modifyTagsFn(
4544
- {
4545
- headTags: headTags.map(formatBasicTag),
4546
- bodyTags: bodyTags.map(formatBasicTag)
4547
- },
4548
- {
4549
- compilation,
4550
- assetPrefix: data.publicPath,
4551
- filename: data.outputName
4552
- }
4553
- );
4618
+ const tags = {
4619
+ headTags: headTags.map(formatBasicTag),
4620
+ bodyTags: bodyTags.map(formatBasicTag)
4621
+ };
4622
+ const modified = this.modifyTagsFn ? await this.modifyTagsFn(tags, {
4623
+ compilation,
4624
+ assetPrefix: data.publicPath,
4625
+ filename: data.outputName
4626
+ }) : tags;
4554
4627
  Object.assign(data, {
4555
- headTags: result.headTags.map(fromBasicTag),
4556
- bodyTags: result.bodyTags.map(fromBasicTag)
4628
+ headTags: modified.headTags.map(fromBasicTag),
4629
+ bodyTags: modified.bodyTags.map(fromBasicTag)
4557
4630
  });
4558
4631
  if (tagConfig) {
4559
4632
  const hash = compilation.hash ?? "";
@@ -4652,7 +4725,7 @@ import {
4652
4725
  castArray as castArray5,
4653
4726
  color as color11,
4654
4727
  deepmerge as deepmerge4,
4655
- fse as fse5,
4728
+ fse as fse6,
4656
4729
  getDistPath as getDistPath5,
4657
4730
  isHtmlDisabled,
4658
4731
  isPlainObject as isPlainObject3,
@@ -4750,7 +4823,7 @@ async function getTemplate(entryName, config, rootPath) {
4750
4823
  }
4751
4824
  existTemplatePath.push(absolutePath);
4752
4825
  }
4753
- const templateContent = await fse5.readFile(absolutePath, "utf-8");
4826
+ const templateContent = await fse6.readFile(absolutePath, "utf-8");
4754
4827
  return {
4755
4828
  templatePath: absolutePath,
4756
4829
  templateContent
@@ -5512,10 +5585,7 @@ var init_splitChunks = __esm({
5512
5585
  rootPath: api.context.rootPath,
5513
5586
  polyfill: config.output.polyfill
5514
5587
  });
5515
- chain.optimization.splitChunks(
5516
- // @ts-expect-error splitChunks type mismatch
5517
- splitChunksOptions
5518
- );
5588
+ chain.optimization.splitChunks(splitChunksOptions);
5519
5589
  }
5520
5590
  );
5521
5591
  }
@@ -5523,16 +5593,22 @@ var init_splitChunks = __esm({
5523
5593
  }
5524
5594
  });
5525
5595
 
5526
- // src/plugins/startUrl.ts
5527
- var startUrl_exports = {};
5528
- __export(startUrl_exports, {
5596
+ // src/plugins/open.ts
5597
+ var open_exports = {};
5598
+ __export(open_exports, {
5529
5599
  openBrowser: () => openBrowser,
5530
- pluginStartUrl: () => pluginStartUrl,
5531
- replacePlaceholder: () => replacePlaceholder
5600
+ pluginOpen: () => pluginOpen,
5601
+ replacePlaceholder: () => replacePlaceholder,
5602
+ resolveUrl: () => resolveUrl
5532
5603
  });
5533
5604
  import { exec } from "child_process";
5534
5605
  import { promisify } from "util";
5535
- import { castArray as castArray6, debug as debug7, logger as logger13 } from "@rsbuild/shared";
5606
+ import {
5607
+ canParse,
5608
+ castArray as castArray6,
5609
+ debug as debug7,
5610
+ logger as logger13
5611
+ } from "@rsbuild/shared";
5536
5612
  async function openBrowser(url2) {
5537
5613
  const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
5538
5614
  if (shouldTryOpenChromeWithAppleScript) {
@@ -5565,30 +5641,45 @@ async function openBrowser(url2) {
5565
5641
  return false;
5566
5642
  }
5567
5643
  }
5568
- function pluginStartUrl() {
5644
+ function resolveUrl(str, base) {
5645
+ if (canParse(str)) {
5646
+ return str;
5647
+ }
5648
+ try {
5649
+ const url2 = new URL(str, base);
5650
+ return url2.href;
5651
+ } catch (e) {
5652
+ throw new Error(
5653
+ "[rsbuild:open]: Invalid input: not a valid URL or pathname"
5654
+ );
5655
+ }
5656
+ }
5657
+ function pluginOpen() {
5569
5658
  return {
5570
- name: "rsbuild:start-url",
5659
+ name: "rsbuild:open",
5571
5660
  setup(api) {
5572
5661
  const onStartServer = async (params) => {
5573
5662
  const { port, routes } = params;
5574
5663
  const config = api.getNormalizedConfig();
5575
- const { startUrl, beforeStartUrl } = config.dev;
5664
+ const { beforeStartUrl } = config.dev;
5665
+ const open = config.server.open || config.dev.startUrl;
5576
5666
  const { https } = api.context.devServer || {};
5577
5667
  const isCodesandbox = process.env.CSB === "true";
5578
- const shouldOpen = Boolean(startUrl) && !isCodesandbox;
5668
+ const shouldOpen = Boolean(open) && !isCodesandbox;
5579
5669
  if (!shouldOpen) {
5580
5670
  return;
5581
5671
  }
5582
5672
  const urls = [];
5583
- if (startUrl === true || !startUrl) {
5584
- const protocol = https ? "https" : "http";
5673
+ const protocol = https ? "https" : "http";
5674
+ const baseUrl = `${protocol}://localhost:${port}`;
5675
+ if (open === true || !open) {
5585
5676
  if (routes.length) {
5586
- urls.push(`${protocol}://localhost:${port}${routes[0].pathname}`);
5677
+ urls.push(`${baseUrl}${routes[0].pathname}`);
5587
5678
  }
5588
5679
  } else {
5589
5680
  urls.push(
5590
- ...castArray6(startUrl).map(
5591
- (item) => replacePlaceholder(item, port)
5681
+ ...castArray6(open).map(
5682
+ (item) => resolveUrl(replacePlaceholder(item, port), baseUrl)
5592
5683
  )
5593
5684
  );
5594
5685
  }
@@ -5614,8 +5705,8 @@ function pluginStartUrl() {
5614
5705
  };
5615
5706
  }
5616
5707
  var execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs;
5617
- var init_startUrl = __esm({
5618
- "src/plugins/startUrl.ts"() {
5708
+ var init_open = __esm({
5709
+ "src/plugins/open.ts"() {
5619
5710
  "use strict";
5620
5711
  init_esm();
5621
5712
  init_constants();
@@ -6027,12 +6118,6 @@ var init_extractChunks = __esm({
6027
6118
  // src/rspack/preload/helpers/determineAsValue.ts
6028
6119
  import path12 from "path";
6029
6120
  import { URL as URL2 } from "url";
6030
- import {
6031
- AUDIO_EXTENSIONS as AUDIO_EXTENSIONS2,
6032
- FONT_EXTENSIONS as FONT_EXTENSIONS2,
6033
- IMAGE_EXTENSIONS as IMAGE_EXTENSIONS2,
6034
- VIDEO_EXTENSIONS as VIDEO_EXTENSIONS2
6035
- } from "@rsbuild/shared";
6036
6121
  function determineAsValue({
6037
6122
  href,
6038
6123
  file
@@ -6042,16 +6127,16 @@ function determineAsValue({
6042
6127
  if (["css"].includes(extension)) {
6043
6128
  return "style";
6044
6129
  }
6045
- if (IMAGE_EXTENSIONS2.includes(extension)) {
6130
+ if (IMAGE_EXTENSIONS.includes(extension)) {
6046
6131
  return "image";
6047
6132
  }
6048
- if (VIDEO_EXTENSIONS2.includes(extension)) {
6133
+ if (VIDEO_EXTENSIONS.includes(extension)) {
6049
6134
  return "video";
6050
6135
  }
6051
- if (AUDIO_EXTENSIONS2.includes(extension)) {
6136
+ if (AUDIO_EXTENSIONS.includes(extension)) {
6052
6137
  return "audio";
6053
6138
  }
6054
- if (FONT_EXTENSIONS2.includes(extension)) {
6139
+ if (FONT_EXTENSIONS.includes(extension)) {
6055
6140
  return "font";
6056
6141
  }
6057
6142
  if (["vtt"].includes(extension)) {
@@ -6063,6 +6148,7 @@ var init_determineAsValue = __esm({
6063
6148
  "src/rspack/preload/helpers/determineAsValue.ts"() {
6064
6149
  "use strict";
6065
6150
  init_esm();
6151
+ init_constants();
6066
6152
  }
6067
6153
  });
6068
6154
 
@@ -6133,7 +6219,7 @@ __export(HtmlPreloadOrPrefetchPlugin_exports, {
6133
6219
  });
6134
6220
  import {
6135
6221
  getPublicPathFromCompiler as getPublicPathFromCompiler4,
6136
- upperFirst,
6222
+ upperFirst as upperFirst2,
6137
6223
  withPublicPath as withPublicPath3
6138
6224
  } from "@rsbuild/shared";
6139
6225
  function filterResourceHints(resourceHints, scripts) {
@@ -6235,7 +6321,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6235
6321
  apply(compiler) {
6236
6322
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
6237
6323
  getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
6238
- `HTML${upperFirst(this.type)}Plugin`,
6324
+ `HTML${upperFirst2(this.type)}Plugin`,
6239
6325
  (htmlPluginData) => {
6240
6326
  this.resourceHints = generateLinks(
6241
6327
  this.options,
@@ -6248,7 +6334,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6248
6334
  }
6249
6335
  );
6250
6336
  getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
6251
- `HTML${upperFirst(this.type)}Plugin`,
6337
+ `HTML${upperFirst2(this.type)}Plugin`,
6252
6338
  (htmlPluginData) => {
6253
6339
  if (this.resourceHints) {
6254
6340
  htmlPluginData.assetTags.styles = [
@@ -6380,7 +6466,7 @@ __export(server_exports, {
6380
6466
  pluginServer: () => pluginServer
6381
6467
  });
6382
6468
  import { isAbsolute as isAbsolute7, join as join11 } from "path";
6383
- import { fse as fse6 } from "@rsbuild/shared";
6469
+ import { fse as fse7 } from "@rsbuild/shared";
6384
6470
  var pluginServer;
6385
6471
  var init_server = __esm({
6386
6472
  "src/plugins/server.ts"() {
@@ -6397,11 +6483,11 @@ var init_server = __esm({
6397
6483
  return;
6398
6484
  }
6399
6485
  const publicDir = isAbsolute7(name) ? name : join11(api.context.rootPath, name);
6400
- if (!fse6.existsSync(publicDir)) {
6486
+ if (!fse7.existsSync(publicDir)) {
6401
6487
  return;
6402
6488
  }
6403
6489
  try {
6404
- await fse6.copy(publicDir, api.context.distPath, {
6490
+ await fse7.copy(publicDir, api.context.distPath, {
6405
6491
  // dereference symlinks
6406
6492
  dereference: true
6407
6493
  });
@@ -6516,7 +6602,6 @@ var init_manifest = __esm({
6516
6602
  name: "rsbuild:manifest",
6517
6603
  setup(api) {
6518
6604
  api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
6519
- const htmlPaths = api.getHTMLPaths();
6520
6605
  const {
6521
6606
  output: { manifest }
6522
6607
  } = api.getNormalizedConfig();
@@ -6525,6 +6610,7 @@ var init_manifest = __esm({
6525
6610
  }
6526
6611
  const fileName = typeof manifest === "string" ? manifest : "manifest.json";
6527
6612
  const { RspackManifestPlugin } = await import("../compiled/rspack-manifest-plugin/index.js");
6613
+ const htmlPaths = api.getHTMLPaths();
6528
6614
  chain.plugin(CHAIN_ID3.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
6529
6615
  {
6530
6616
  fileName,
@@ -6653,7 +6739,7 @@ __export(rspackProfile_exports, {
6653
6739
  });
6654
6740
  import inspector from "inspector";
6655
6741
  import path13 from "path";
6656
- import { fse as fse7 } from "@rsbuild/shared";
6742
+ import { fse as fse8 } from "@rsbuild/shared";
6657
6743
  import { logger as logger15 } from "@rsbuild/shared";
6658
6744
  import { rspack as rspack9 } from "@rspack/core";
6659
6745
  var stopProfiler, pluginRspackProfile;
@@ -6670,7 +6756,7 @@ var init_rspackProfile = __esm({
6670
6756
  logger15.error("Failed to generate JS CPU profile:", error);
6671
6757
  return;
6672
6758
  }
6673
- fse7.writeFileSync(output, JSON.stringify(param.profile));
6759
+ fse8.writeFileSync(output, JSON.stringify(param.profile));
6674
6760
  });
6675
6761
  };
6676
6762
  pluginRspackProfile = () => ({
@@ -6696,7 +6782,7 @@ var init_rspackProfile = __esm({
6696
6782
  const cpuProfilePath = path13.join(profileDir, "jscpuprofile.json");
6697
6783
  const loggingFilePath = path13.join(profileDir, "logging.json");
6698
6784
  const onStart = () => {
6699
- fse7.ensureDirSync(profileDir);
6785
+ fse8.ensureDirSync(profileDir);
6700
6786
  if (enableProfileTrace) {
6701
6787
  rspack9.experimental_registerGlobalTrace(
6702
6788
  "trace",
@@ -6720,7 +6806,7 @@ var init_rspackProfile = __esm({
6720
6806
  logging: "verbose",
6721
6807
  loggingTrace: true
6722
6808
  });
6723
- fse7.writeFileSync(loggingFilePath, JSON.stringify(logging));
6809
+ fse8.writeFileSync(loggingFilePath, JSON.stringify(logging));
6724
6810
  }
6725
6811
  });
6726
6812
  api.onExit(() => {
@@ -6758,12 +6844,10 @@ var init_lazyCompilation = __esm({
6758
6844
  if (!options) {
6759
6845
  return;
6760
6846
  }
6761
- const clientRegExp = /[\\/]core[\\/]dist[\\/]client[\\/]/;
6762
6847
  const cssRegExp = /\.(?:css|less|sass|scss|styl|stylus)$/;
6763
6848
  const isExcludedModule = (name) => {
6764
6849
  return (
6765
- // alway include Rsbuild client code, such as HMR
6766
- clientRegExp.test(name) || // exclude CSS files because Rspack does not support it yet
6850
+ // exclude CSS files because Rspack does not support it yet
6767
6851
  // TODO: remove this after Rspack supporting it
6768
6852
  cssRegExp.test(name)
6769
6853
  );
@@ -7061,7 +7145,7 @@ async function applyDefaultPlugins(pluginManager, context) {
7061
7145
  const { pluginSwc: pluginSwc2 } = await Promise.resolve().then(() => (init_swc(), swc_exports));
7062
7146
  const { pluginExternals: pluginExternals2 } = await Promise.resolve().then(() => (init_externals(), externals_exports));
7063
7147
  const { pluginSplitChunks: pluginSplitChunks2 } = await Promise.resolve().then(() => (init_splitChunks(), splitChunks_exports));
7064
- const { pluginStartUrl: pluginStartUrl2 } = await Promise.resolve().then(() => (init_startUrl(), startUrl_exports));
7148
+ const { pluginOpen: pluginOpen2 } = await Promise.resolve().then(() => (init_open(), open_exports));
7065
7149
  const { pluginInlineChunk: pluginInlineChunk2 } = await Promise.resolve().then(() => (init_inlineChunk(), inlineChunk_exports));
7066
7150
  const { pluginBundleAnalyzer: pluginBundleAnalyzer2 } = await Promise.resolve().then(() => (init_bundleAnalyzer(), bundleAnalyzer_exports));
7067
7151
  const { pluginRsdoctor: pluginRsdoctor2 } = await Promise.resolve().then(() => (init_rsdoctor(), rsdoctor_exports));
@@ -7099,7 +7183,7 @@ async function applyDefaultPlugins(pluginManager, context) {
7099
7183
  pluginSwc2(),
7100
7184
  pluginExternals2(),
7101
7185
  pluginSplitChunks2(),
7102
- pluginStartUrl2(),
7186
+ pluginOpen2(),
7103
7187
  pluginInlineChunk2(),
7104
7188
  pluginBundleAnalyzer2(),
7105
7189
  pluginRsdoctor2(),
@@ -7247,9 +7331,9 @@ async function init({
7247
7331
  ...envs.publicVars,
7248
7332
  ...config.source.define
7249
7333
  };
7250
- if (commonOpts.open && !config.dev?.startUrl) {
7251
- config.dev ||= {};
7252
- config.dev.startUrl = commonOpts.open;
7334
+ if (commonOpts.open && !config.server?.open) {
7335
+ config.server ||= {};
7336
+ config.server.open = commonOpts.open;
7253
7337
  }
7254
7338
  if (commonOpts.host) {
7255
7339
  config.server ||= {};
@@ -7302,10 +7386,12 @@ __export(internal_exports, {
7302
7386
  initHooks: () => initHooks,
7303
7387
  initPlugins: () => initPlugins,
7304
7388
  initRsbuildConfig: () => initRsbuildConfig,
7389
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
7305
7390
  prepareCli: () => prepareCli,
7306
7391
  runCli: () => runCli,
7307
7392
  setHTMLPlugin: () => setHTMLPlugin,
7308
- startProdServer: () => startProdServer
7393
+ startProdServer: () => startProdServer,
7394
+ stringifyConfig: () => stringifyConfig
7309
7395
  });
7310
7396
  init_esm();
7311
7397
 
@@ -7330,7 +7416,7 @@ var applyServerOptions = (command) => {
7330
7416
  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");
7331
7417
  };
7332
7418
  function runCli() {
7333
- program.name("rsbuild").usage("<command> [options]").version("0.7.3");
7419
+ program.name("rsbuild").usage("<command> [options]").version("0.7.4");
7334
7420
  const devCommand = program.command("dev");
7335
7421
  const buildCommand = program.command("build");
7336
7422
  const previewCommand = program.command("preview");
@@ -7421,7 +7507,7 @@ function prepareCli() {
7421
7507
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7422
7508
  console.log();
7423
7509
  }
7424
- logger19.greet(` ${`Rsbuild v${"0.7.3"}`}
7510
+ logger19.greet(` ${`Rsbuild v${"0.7.4"}`}
7425
7511
  `);
7426
7512
  }
7427
7513
 
@@ -7429,6 +7515,7 @@ function prepareCli() {
7429
7515
  init_pluginManager();
7430
7516
  init_initHooks();
7431
7517
  init_initConfigs();
7518
+ init_config();
7432
7519
  init_pluginHelper();
7433
7520
  init_helpers();
7434
7521
  init_rspackConfig();
@@ -7448,7 +7535,7 @@ init_config();
7448
7535
  init_mergeConfig();
7449
7536
  init_constants();
7450
7537
  import { logger as logger20 } from "@rsbuild/shared";
7451
- var version = "0.7.3";
7538
+ var version = "0.7.4";
7452
7539
  export {
7453
7540
  PLUGIN_CSS_NAME,
7454
7541
  PLUGIN_SWC_NAME,