@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.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.5",
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
@@ -5176,7 +5249,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
5176
5249
  }
5177
5250
  };
5178
5251
  }
5179
- async function applyCoreJs(swcConfig, chain, polyfillMode) {
5252
+ async function applyCoreJs(swcConfig, polyfillMode) {
5180
5253
  const coreJsPath = __require.resolve("core-js/package.json");
5181
5254
  const version2 = getCoreJsVersion(coreJsPath);
5182
5255
  const coreJsDir = path11.dirname(coreJsPath);
@@ -5184,9 +5257,7 @@ async function applyCoreJs(swcConfig, chain, polyfillMode) {
5184
5257
  if (polyfillMode === "usage") {
5185
5258
  swcConfig.env.shippedProposals = true;
5186
5259
  }
5187
- chain.resolve.alias.merge({
5188
- "core-js": coreJsDir
5189
- });
5260
+ return coreJsDir;
5190
5261
  }
5191
5262
  function applyTransformImport(swcConfig, pluginImport) {
5192
5263
  if (pluginImport !== false && pluginImport) {
@@ -5231,6 +5302,9 @@ var init_swc = __esm({
5231
5302
  handler: async (chain, { CHAIN_ID: CHAIN_ID3, target }) => {
5232
5303
  const config = api.getNormalizedConfig();
5233
5304
  const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto");
5305
+ const dataUriRule = chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
5306
+ or: ["text/javascript", "application/javascript"]
5307
+ });
5234
5308
  applyScriptCondition({
5235
5309
  rule,
5236
5310
  chain,
@@ -5258,7 +5332,10 @@ var init_swc = __esm({
5258
5332
  swcConfig.env.mode = void 0;
5259
5333
  } else {
5260
5334
  swcConfig.env.mode = polyfillMode;
5261
- await applyCoreJs(swcConfig, chain, polyfillMode);
5335
+ const coreJsDir = await applyCoreJs(swcConfig, polyfillMode);
5336
+ for (const item of [rule, dataUriRule]) {
5337
+ item.resolve.alias.set("core-js", coreJsDir);
5338
+ }
5262
5339
  }
5263
5340
  }
5264
5341
  const mergedSwcConfig = reduceConfigs2({
@@ -5267,9 +5344,7 @@ var init_swc = __esm({
5267
5344
  mergeFn: deepmerge5
5268
5345
  });
5269
5346
  rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
5270
- chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
5271
- or: ["text/javascript", "application/javascript"]
5272
- }).resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(cloneDeep(mergedSwcConfig));
5347
+ dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(cloneDeep(mergedSwcConfig));
5273
5348
  }
5274
5349
  });
5275
5350
  }
@@ -5512,10 +5587,7 @@ var init_splitChunks = __esm({
5512
5587
  rootPath: api.context.rootPath,
5513
5588
  polyfill: config.output.polyfill
5514
5589
  });
5515
- chain.optimization.splitChunks(
5516
- // @ts-expect-error splitChunks type mismatch
5517
- splitChunksOptions
5518
- );
5590
+ chain.optimization.splitChunks(splitChunksOptions);
5519
5591
  }
5520
5592
  );
5521
5593
  }
@@ -5523,16 +5595,22 @@ var init_splitChunks = __esm({
5523
5595
  }
5524
5596
  });
5525
5597
 
5526
- // src/plugins/startUrl.ts
5527
- var startUrl_exports = {};
5528
- __export(startUrl_exports, {
5598
+ // src/plugins/open.ts
5599
+ var open_exports = {};
5600
+ __export(open_exports, {
5529
5601
  openBrowser: () => openBrowser,
5530
- pluginStartUrl: () => pluginStartUrl,
5531
- replacePlaceholder: () => replacePlaceholder
5602
+ pluginOpen: () => pluginOpen,
5603
+ replacePlaceholder: () => replacePlaceholder,
5604
+ resolveUrl: () => resolveUrl
5532
5605
  });
5533
5606
  import { exec } from "child_process";
5534
5607
  import { promisify } from "util";
5535
- import { castArray as castArray6, debug as debug7, logger as logger13 } from "@rsbuild/shared";
5608
+ import {
5609
+ canParse,
5610
+ castArray as castArray6,
5611
+ debug as debug7,
5612
+ logger as logger13
5613
+ } from "@rsbuild/shared";
5536
5614
  async function openBrowser(url2) {
5537
5615
  const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
5538
5616
  if (shouldTryOpenChromeWithAppleScript) {
@@ -5565,30 +5643,44 @@ async function openBrowser(url2) {
5565
5643
  return false;
5566
5644
  }
5567
5645
  }
5568
- function pluginStartUrl() {
5646
+ function resolveUrl(str, base) {
5647
+ if (canParse(str)) {
5648
+ return str;
5649
+ }
5650
+ try {
5651
+ const url2 = new URL(str, base);
5652
+ return url2.href;
5653
+ } catch (e) {
5654
+ throw new Error(
5655
+ "[rsbuild:open]: Invalid input: not a valid URL or pathname"
5656
+ );
5657
+ }
5658
+ }
5659
+ function pluginOpen() {
5569
5660
  return {
5570
- name: "rsbuild:start-url",
5661
+ name: "rsbuild:open",
5571
5662
  setup(api) {
5572
5663
  const onStartServer = async (params) => {
5573
5664
  const { port, routes } = params;
5574
5665
  const config = api.getNormalizedConfig();
5575
- const { startUrl, beforeStartUrl } = config.dev;
5576
5666
  const { https } = api.context.devServer || {};
5667
+ const { targets, before } = normalizeOpenConfig(config);
5577
5668
  const isCodesandbox = process.env.CSB === "true";
5578
- const shouldOpen = Boolean(startUrl) && !isCodesandbox;
5669
+ const shouldOpen = targets !== void 0 && !isCodesandbox;
5579
5670
  if (!shouldOpen) {
5580
5671
  return;
5581
5672
  }
5582
5673
  const urls = [];
5583
- if (startUrl === true || !startUrl) {
5584
- const protocol = https ? "https" : "http";
5674
+ const protocol = https ? "https" : "http";
5675
+ const baseUrl = `${protocol}://localhost:${port}`;
5676
+ if (!targets.length) {
5585
5677
  if (routes.length) {
5586
- urls.push(`${protocol}://localhost:${port}${routes[0].pathname}`);
5678
+ urls.push(`${baseUrl}${routes[0].pathname}`);
5587
5679
  }
5588
5680
  } else {
5589
5681
  urls.push(
5590
- ...castArray6(startUrl).map(
5591
- (item) => replacePlaceholder(item, port)
5682
+ ...targets.map(
5683
+ (target) => resolveUrl(replacePlaceholder(target, port), baseUrl)
5592
5684
  )
5593
5685
  );
5594
5686
  }
@@ -5600,22 +5692,19 @@ function pluginStartUrl() {
5600
5692
  }
5601
5693
  }
5602
5694
  };
5603
- if (beforeStartUrl) {
5604
- Promise.all(castArray6(beforeStartUrl).map((fn) => fn())).then(
5605
- openUrls
5606
- );
5607
- } else {
5608
- openUrls();
5695
+ if (before) {
5696
+ await before();
5609
5697
  }
5698
+ openUrls();
5610
5699
  };
5611
5700
  api.onAfterStartDevServer(onStartServer);
5612
5701
  api.onAfterStartProdServer(onStartServer);
5613
5702
  }
5614
5703
  };
5615
5704
  }
5616
- var execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs;
5617
- var init_startUrl = __esm({
5618
- "src/plugins/startUrl.ts"() {
5705
+ var execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs, normalizeOpenConfig;
5706
+ var init_open = __esm({
5707
+ "src/plugins/open.ts"() {
5619
5708
  "use strict";
5620
5709
  init_esm();
5621
5710
  init_constants();
@@ -5640,6 +5729,26 @@ var init_startUrl = __esm({
5640
5729
  };
5641
5730
  replacePlaceholder = (url2, port) => url2.replace(/<port>/g, String(port));
5642
5731
  openedURLs = [];
5732
+ normalizeOpenConfig = (config) => {
5733
+ const open = config.server.open || config.dev.startUrl;
5734
+ const { beforeStartUrl } = config.dev;
5735
+ if (open === false) {
5736
+ return {};
5737
+ }
5738
+ if (open === true) {
5739
+ return { targets: [], before: beforeStartUrl };
5740
+ }
5741
+ if (typeof open === "string") {
5742
+ return { targets: [open], before: beforeStartUrl };
5743
+ }
5744
+ if (Array.isArray(open)) {
5745
+ return { targets: open, before: beforeStartUrl };
5746
+ }
5747
+ return {
5748
+ targets: open.target ? castArray6(open.target) : [],
5749
+ before: open.before
5750
+ };
5751
+ };
5643
5752
  }
5644
5753
  });
5645
5754
 
@@ -6027,12 +6136,6 @@ var init_extractChunks = __esm({
6027
6136
  // src/rspack/preload/helpers/determineAsValue.ts
6028
6137
  import path12 from "path";
6029
6138
  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
6139
  function determineAsValue({
6037
6140
  href,
6038
6141
  file
@@ -6042,16 +6145,16 @@ function determineAsValue({
6042
6145
  if (["css"].includes(extension)) {
6043
6146
  return "style";
6044
6147
  }
6045
- if (IMAGE_EXTENSIONS2.includes(extension)) {
6148
+ if (IMAGE_EXTENSIONS.includes(extension)) {
6046
6149
  return "image";
6047
6150
  }
6048
- if (VIDEO_EXTENSIONS2.includes(extension)) {
6151
+ if (VIDEO_EXTENSIONS.includes(extension)) {
6049
6152
  return "video";
6050
6153
  }
6051
- if (AUDIO_EXTENSIONS2.includes(extension)) {
6154
+ if (AUDIO_EXTENSIONS.includes(extension)) {
6052
6155
  return "audio";
6053
6156
  }
6054
- if (FONT_EXTENSIONS2.includes(extension)) {
6157
+ if (FONT_EXTENSIONS.includes(extension)) {
6055
6158
  return "font";
6056
6159
  }
6057
6160
  if (["vtt"].includes(extension)) {
@@ -6063,6 +6166,7 @@ var init_determineAsValue = __esm({
6063
6166
  "src/rspack/preload/helpers/determineAsValue.ts"() {
6064
6167
  "use strict";
6065
6168
  init_esm();
6169
+ init_constants();
6066
6170
  }
6067
6171
  });
6068
6172
 
@@ -6133,7 +6237,7 @@ __export(HtmlPreloadOrPrefetchPlugin_exports, {
6133
6237
  });
6134
6238
  import {
6135
6239
  getPublicPathFromCompiler as getPublicPathFromCompiler4,
6136
- upperFirst,
6240
+ upperFirst as upperFirst2,
6137
6241
  withPublicPath as withPublicPath3
6138
6242
  } from "@rsbuild/shared";
6139
6243
  function filterResourceHints(resourceHints, scripts) {
@@ -6235,7 +6339,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6235
6339
  apply(compiler) {
6236
6340
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
6237
6341
  getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
6238
- `HTML${upperFirst(this.type)}Plugin`,
6342
+ `HTML${upperFirst2(this.type)}Plugin`,
6239
6343
  (htmlPluginData) => {
6240
6344
  this.resourceHints = generateLinks(
6241
6345
  this.options,
@@ -6248,7 +6352,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6248
6352
  }
6249
6353
  );
6250
6354
  getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
6251
- `HTML${upperFirst(this.type)}Plugin`,
6355
+ `HTML${upperFirst2(this.type)}Plugin`,
6252
6356
  (htmlPluginData) => {
6253
6357
  if (this.resourceHints) {
6254
6358
  htmlPluginData.assetTags.styles = [
@@ -6380,7 +6484,7 @@ __export(server_exports, {
6380
6484
  pluginServer: () => pluginServer
6381
6485
  });
6382
6486
  import { isAbsolute as isAbsolute7, join as join11 } from "path";
6383
- import { fse as fse6 } from "@rsbuild/shared";
6487
+ import { fse as fse7 } from "@rsbuild/shared";
6384
6488
  var pluginServer;
6385
6489
  var init_server = __esm({
6386
6490
  "src/plugins/server.ts"() {
@@ -6397,11 +6501,11 @@ var init_server = __esm({
6397
6501
  return;
6398
6502
  }
6399
6503
  const publicDir = isAbsolute7(name) ? name : join11(api.context.rootPath, name);
6400
- if (!fse6.existsSync(publicDir)) {
6504
+ if (!fse7.existsSync(publicDir)) {
6401
6505
  return;
6402
6506
  }
6403
6507
  try {
6404
- await fse6.copy(publicDir, api.context.distPath, {
6508
+ await fse7.copy(publicDir, api.context.distPath, {
6405
6509
  // dereference symlinks
6406
6510
  dereference: true
6407
6511
  });
@@ -6516,7 +6620,6 @@ var init_manifest = __esm({
6516
6620
  name: "rsbuild:manifest",
6517
6621
  setup(api) {
6518
6622
  api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
6519
- const htmlPaths = api.getHTMLPaths();
6520
6623
  const {
6521
6624
  output: { manifest }
6522
6625
  } = api.getNormalizedConfig();
@@ -6525,6 +6628,7 @@ var init_manifest = __esm({
6525
6628
  }
6526
6629
  const fileName = typeof manifest === "string" ? manifest : "manifest.json";
6527
6630
  const { RspackManifestPlugin } = await import("../compiled/rspack-manifest-plugin/index.js");
6631
+ const htmlPaths = api.getHTMLPaths();
6528
6632
  chain.plugin(CHAIN_ID3.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
6529
6633
  {
6530
6634
  fileName,
@@ -6653,7 +6757,7 @@ __export(rspackProfile_exports, {
6653
6757
  });
6654
6758
  import inspector from "inspector";
6655
6759
  import path13 from "path";
6656
- import { fse as fse7 } from "@rsbuild/shared";
6760
+ import { fse as fse8 } from "@rsbuild/shared";
6657
6761
  import { logger as logger15 } from "@rsbuild/shared";
6658
6762
  import { rspack as rspack9 } from "@rspack/core";
6659
6763
  var stopProfiler, pluginRspackProfile;
@@ -6670,7 +6774,7 @@ var init_rspackProfile = __esm({
6670
6774
  logger15.error("Failed to generate JS CPU profile:", error);
6671
6775
  return;
6672
6776
  }
6673
- fse7.writeFileSync(output, JSON.stringify(param.profile));
6777
+ fse8.writeFileSync(output, JSON.stringify(param.profile));
6674
6778
  });
6675
6779
  };
6676
6780
  pluginRspackProfile = () => ({
@@ -6696,7 +6800,7 @@ var init_rspackProfile = __esm({
6696
6800
  const cpuProfilePath = path13.join(profileDir, "jscpuprofile.json");
6697
6801
  const loggingFilePath = path13.join(profileDir, "logging.json");
6698
6802
  const onStart = () => {
6699
- fse7.ensureDirSync(profileDir);
6803
+ fse8.ensureDirSync(profileDir);
6700
6804
  if (enableProfileTrace) {
6701
6805
  rspack9.experimental_registerGlobalTrace(
6702
6806
  "trace",
@@ -6720,7 +6824,7 @@ var init_rspackProfile = __esm({
6720
6824
  logging: "verbose",
6721
6825
  loggingTrace: true
6722
6826
  });
6723
- fse7.writeFileSync(loggingFilePath, JSON.stringify(logging));
6827
+ fse8.writeFileSync(loggingFilePath, JSON.stringify(logging));
6724
6828
  }
6725
6829
  });
6726
6830
  api.onExit(() => {
@@ -6758,12 +6862,10 @@ var init_lazyCompilation = __esm({
6758
6862
  if (!options) {
6759
6863
  return;
6760
6864
  }
6761
- const clientRegExp = /[\\/]core[\\/]dist[\\/]client[\\/]/;
6762
6865
  const cssRegExp = /\.(?:css|less|sass|scss|styl|stylus)$/;
6763
6866
  const isExcludedModule = (name) => {
6764
6867
  return (
6765
- // alway include Rsbuild client code, such as HMR
6766
- clientRegExp.test(name) || // exclude CSS files because Rspack does not support it yet
6868
+ // exclude CSS files because Rspack does not support it yet
6767
6869
  // TODO: remove this after Rspack supporting it
6768
6870
  cssRegExp.test(name)
6769
6871
  );
@@ -7061,7 +7163,7 @@ async function applyDefaultPlugins(pluginManager, context) {
7061
7163
  const { pluginSwc: pluginSwc2 } = await Promise.resolve().then(() => (init_swc(), swc_exports));
7062
7164
  const { pluginExternals: pluginExternals2 } = await Promise.resolve().then(() => (init_externals(), externals_exports));
7063
7165
  const { pluginSplitChunks: pluginSplitChunks2 } = await Promise.resolve().then(() => (init_splitChunks(), splitChunks_exports));
7064
- const { pluginStartUrl: pluginStartUrl2 } = await Promise.resolve().then(() => (init_startUrl(), startUrl_exports));
7166
+ const { pluginOpen: pluginOpen2 } = await Promise.resolve().then(() => (init_open(), open_exports));
7065
7167
  const { pluginInlineChunk: pluginInlineChunk2 } = await Promise.resolve().then(() => (init_inlineChunk(), inlineChunk_exports));
7066
7168
  const { pluginBundleAnalyzer: pluginBundleAnalyzer2 } = await Promise.resolve().then(() => (init_bundleAnalyzer(), bundleAnalyzer_exports));
7067
7169
  const { pluginRsdoctor: pluginRsdoctor2 } = await Promise.resolve().then(() => (init_rsdoctor(), rsdoctor_exports));
@@ -7099,7 +7201,7 @@ async function applyDefaultPlugins(pluginManager, context) {
7099
7201
  pluginSwc2(),
7100
7202
  pluginExternals2(),
7101
7203
  pluginSplitChunks2(),
7102
- pluginStartUrl2(),
7204
+ pluginOpen2(),
7103
7205
  pluginInlineChunk2(),
7104
7206
  pluginBundleAnalyzer2(),
7105
7207
  pluginRsdoctor2(),
@@ -7247,9 +7349,9 @@ async function init({
7247
7349
  ...envs.publicVars,
7248
7350
  ...config.source.define
7249
7351
  };
7250
- if (commonOpts.open && !config.dev?.startUrl) {
7251
- config.dev ||= {};
7252
- config.dev.startUrl = commonOpts.open;
7352
+ if (commonOpts.open && !config.server?.open) {
7353
+ config.server ||= {};
7354
+ config.server.open = commonOpts.open;
7253
7355
  }
7254
7356
  if (commonOpts.host) {
7255
7357
  config.server ||= {};
@@ -7302,10 +7404,12 @@ __export(internal_exports, {
7302
7404
  initHooks: () => initHooks,
7303
7405
  initPlugins: () => initPlugins,
7304
7406
  initRsbuildConfig: () => initRsbuildConfig,
7407
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
7305
7408
  prepareCli: () => prepareCli,
7306
7409
  runCli: () => runCli,
7307
7410
  setHTMLPlugin: () => setHTMLPlugin,
7308
- startProdServer: () => startProdServer
7411
+ startProdServer: () => startProdServer,
7412
+ stringifyConfig: () => stringifyConfig
7309
7413
  });
7310
7414
  init_esm();
7311
7415
 
@@ -7330,7 +7434,7 @@ var applyServerOptions = (command) => {
7330
7434
  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
7435
  };
7332
7436
  function runCli() {
7333
- program.name("rsbuild").usage("<command> [options]").version("0.7.3");
7437
+ program.name("rsbuild").usage("<command> [options]").version("0.7.5");
7334
7438
  const devCommand = program.command("dev");
7335
7439
  const buildCommand = program.command("build");
7336
7440
  const previewCommand = program.command("preview");
@@ -7421,7 +7525,7 @@ function prepareCli() {
7421
7525
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7422
7526
  console.log();
7423
7527
  }
7424
- logger19.greet(` ${`Rsbuild v${"0.7.3"}`}
7528
+ logger19.greet(` ${`Rsbuild v${"0.7.5"}`}
7425
7529
  `);
7426
7530
  }
7427
7531
 
@@ -7429,6 +7533,7 @@ function prepareCli() {
7429
7533
  init_pluginManager();
7430
7534
  init_initHooks();
7431
7535
  init_initConfigs();
7536
+ init_config();
7432
7537
  init_pluginHelper();
7433
7538
  init_helpers();
7434
7539
  init_rspackConfig();
@@ -7448,7 +7553,7 @@ init_config();
7448
7553
  init_mergeConfig();
7449
7554
  init_constants();
7450
7555
  import { logger as logger20 } from "@rsbuild/shared";
7451
- var version = "0.7.3";
7556
+ var version = "0.7.5";
7452
7557
  export {
7453
7558
  PLUGIN_CSS_NAME,
7454
7559
  PLUGIN_SWC_NAME,