@rsbuild/core 0.7.2 → 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.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,13 +675,16 @@ 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"
597
682
  });
598
683
  getDefaultSecurityConfig = () => ({
599
- nonce: ""
684
+ nonce: "",
685
+ sri: {
686
+ enable: false
687
+ }
600
688
  });
601
689
  getDefaultToolsConfig = () => ({
602
690
  cssExtract: {
@@ -619,27 +707,27 @@ var init_config = __esm({
619
707
  getDefaultOutputConfig = () => ({
620
708
  targets: ["web"],
621
709
  distPath: {
622
- root: import_shared5.ROOT_DIST_DIR,
623
- js: import_shared5.JS_DIST_DIR,
624
- css: import_shared5.CSS_DIST_DIR,
625
- svg: import_shared5.SVG_DIST_DIR,
626
- font: import_shared5.FONT_DIST_DIR,
627
- html: import_shared5.HTML_DIST_DIR,
628
- wasm: import_shared5.WASM_DIST_DIR,
629
- image: import_shared5.IMAGE_DIST_DIR,
630
- media: import_shared5.MEDIA_DIST_DIR,
631
- server: import_shared5.SERVER_DIST_DIR,
632
- 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
633
721
  },
634
722
  assetPrefix: import_shared5.DEFAULT_ASSET_PREFIX,
635
723
  filename: {},
636
724
  charset: "ascii",
637
725
  polyfill: "usage",
638
726
  dataUriLimit: {
639
- svg: import_shared5.DEFAULT_DATA_URL_SIZE,
640
- font: import_shared5.DEFAULT_DATA_URL_SIZE,
641
- image: import_shared5.DEFAULT_DATA_URL_SIZE,
642
- 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
643
731
  },
644
732
  legalComments: "linked",
645
733
  injectStyles: false,
@@ -765,15 +853,15 @@ function loadEnv({
765
853
  publicVars
766
854
  };
767
855
  }
768
- var import_node_fs2, import_node_path5, import_shared6, import_dotenv_expand, import_dotenv;
856
+ var import_node_fs2, import_node_path5, import_shared6, import_dotenv, import_dotenv_expand;
769
857
  var init_loadEnv = __esm({
770
858
  "src/loadEnv.ts"() {
771
859
  "use strict";
772
860
  import_node_fs2 = __toESM(require("fs"));
773
861
  import_node_path5 = require("path");
774
862
  import_shared6 = require("@rsbuild/shared");
775
- import_dotenv_expand = require("../compiled/dotenv-expand/index.js");
776
863
  import_dotenv = require("../compiled/dotenv/index.js");
864
+ import_dotenv_expand = require("../compiled/dotenv-expand/index.js");
777
865
  init_helpers();
778
866
  }
779
867
  });
@@ -849,11 +937,10 @@ function getEntryObject(config, target) {
849
937
  if (!config.source?.entry) {
850
938
  return {};
851
939
  }
852
- return (0, import_shared8.mergeChainedOptions)({
853
- defaults: {},
854
- options: config.source?.entry,
855
- utils: { target },
856
- useObjectParam: true
940
+ return (0, import_shared8.reduceConfigsMergeContext)({
941
+ initial: {},
942
+ config: config.source?.entry,
943
+ ctx: { target }
857
944
  });
858
945
  }
859
946
  var import_shared8, pluginEntry;
@@ -916,7 +1003,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
916
1003
  return {
917
1004
  entry: getEntryObject(config, "web"),
918
1005
  targets: config.output?.targets || [],
919
- version: "0.7.2",
1006
+ version: "0.7.4",
920
1007
  rootPath,
921
1008
  distPath,
922
1009
  cachePath,
@@ -1333,13 +1420,13 @@ async function inspectConfig({
1333
1420
  ...context.normalizedConfig,
1334
1421
  pluginNames: pluginManager.getPlugins().map((p) => p.name)
1335
1422
  };
1336
- const rawRsbuildConfig = await (0, import_shared12.stringifyConfig)(
1423
+ const rawRsbuildConfig = await stringifyConfig(
1337
1424
  rsbuildDebugConfig,
1338
1425
  inspectOptions.verbose
1339
1426
  );
1340
1427
  const rawBundlerConfigs = await Promise.all(
1341
1428
  rspackConfigs.map(
1342
- (config) => (0, import_shared12.stringifyConfig)(config, inspectOptions.verbose)
1429
+ (config) => stringifyConfig(config, inspectOptions.verbose)
1343
1430
  )
1344
1431
  );
1345
1432
  let outputPath = inspectOptions.outputPath || context.distPath;
@@ -1347,7 +1434,7 @@ async function inspectConfig({
1347
1434
  outputPath = (0, import_node_path8.join)(context.rootPath, outputPath);
1348
1435
  }
1349
1436
  if (inspectOptions.writeToDisk) {
1350
- await (0, import_shared12.outputInspectConfigFiles)({
1437
+ await outputInspectConfigFiles({
1351
1438
  rsbuildConfig: context.normalizedConfig,
1352
1439
  rawRsbuildConfig,
1353
1440
  bundlerConfigs: rawBundlerConfigs,
@@ -1373,6 +1460,7 @@ var init_inspectConfig = __esm({
1373
1460
  "use strict";
1374
1461
  import_node_path8 = require("path");
1375
1462
  import_shared12 = require("@rsbuild/shared");
1463
+ init_config();
1376
1464
  init_initConfigs();
1377
1465
  }
1378
1466
  });
@@ -1385,10 +1473,10 @@ async function modifyRspackConfig(context, rspackConfig, utils) {
1385
1473
  utils
1386
1474
  );
1387
1475
  if (context.config.tools?.rspack) {
1388
- modifiedConfig = (0, import_shared13.mergeChainedOptions)({
1389
- defaults: modifiedConfig,
1390
- options: context.config.tools.rspack,
1391
- utils,
1476
+ modifiedConfig = await (0, import_shared13.reduceConfigsAsyncWithContext)({
1477
+ initial: modifiedConfig,
1478
+ config: context.config.tools.rspack,
1479
+ ctx: utils,
1392
1480
  mergeFn: utils.mergeConfig
1393
1481
  });
1394
1482
  }
@@ -2161,6 +2249,7 @@ var init_helper = __esm({
2161
2249
  import_node_net = __toESM(require("net"));
2162
2250
  import_node_os = __toESM(require("os"));
2163
2251
  import_shared20 = require("@rsbuild/shared");
2252
+ init_constants();
2164
2253
  formatPrefix = (prefix) => {
2165
2254
  if (!prefix) {
2166
2255
  return "/";
@@ -2235,10 +2324,10 @@ var init_helper = __esm({
2235
2324
  config,
2236
2325
  getPortSilently
2237
2326
  }) => {
2238
- const host = config.server.host || import_shared20.DEFAULT_DEV_HOST;
2327
+ const host = config.server.host || DEFAULT_DEV_HOST;
2239
2328
  const port = await getPort({
2240
2329
  host,
2241
- port: config.server.port || import_shared20.DEFAULT_PORT,
2330
+ port: config.server.port || DEFAULT_PORT,
2242
2331
  strictPort: config.server.strictPort || false,
2243
2332
  silent: getPortSilently
2244
2333
  });
@@ -2312,7 +2401,7 @@ var init_helper = __esm({
2312
2401
  port,
2313
2402
  host
2314
2403
  }) => {
2315
- if (host && host !== import_shared20.DEFAULT_DEV_HOST) {
2404
+ if (host && host !== DEFAULT_DEV_HOST) {
2316
2405
  return [
2317
2406
  {
2318
2407
  label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
@@ -2774,7 +2863,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2774
2863
  dev: devConfig,
2775
2864
  server: serverConfig,
2776
2865
  output: {
2777
- distPath: config.output.distPath.root || import_shared22.ROOT_DIST_DIR
2866
+ distPath: config.output.distPath.root || ROOT_DIST_DIR
2778
2867
  },
2779
2868
  outputFileSystem
2780
2869
  });
@@ -2849,6 +2938,7 @@ var init_devServer = __esm({
2849
2938
  "use strict";
2850
2939
  import_node_fs3 = __toESM(require("fs"));
2851
2940
  import_shared22 = require("@rsbuild/shared");
2941
+ init_constants();
2852
2942
  init_getDevMiddlewares();
2853
2943
  init_helper();
2854
2944
  init_httpServer();
@@ -2879,7 +2969,7 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
2879
2969
  {
2880
2970
  pwd: context.rootPath,
2881
2971
  output: {
2882
- path: config.output.distPath.root || import_shared23.ROOT_DIST_DIR,
2972
+ path: config.output.distPath.root || ROOT_DIST_DIR,
2883
2973
  assetPrefix: config.output.assetPrefix
2884
2974
  },
2885
2975
  serverConfig
@@ -2940,6 +3030,7 @@ var init_prodServer = __esm({
2940
3030
  "use strict";
2941
3031
  import_node_path11 = require("path");
2942
3032
  import_shared23 = require("@rsbuild/shared");
3033
+ init_constants();
2943
3034
  init_helper();
2944
3035
  init_httpServer();
2945
3036
  init_middlewares();
@@ -3200,12 +3291,12 @@ var init_basic = __esm({
3200
3291
  name: "rsbuild:basic",
3201
3292
  setup(api) {
3202
3293
  api.modifyBundlerChain(
3203
- (chain, { env, isProd: isProd4, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3294
+ (chain, { env, isProd: isProd5, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3204
3295
  const config = api.getNormalizedConfig();
3205
3296
  chain.name(import_shared25.TARGET_ID_MAP[target]);
3206
3297
  chain.devtool((0, import_shared25.getJsSourceMap)(config));
3207
3298
  chain.context(api.context.rootPath);
3208
- chain.mode(isProd4 ? "production" : "development");
3299
+ chain.mode(isProd5 ? "production" : "development");
3209
3300
  chain.merge({
3210
3301
  infrastructureLogging: {
3211
3302
  // Using `error` level to avoid `cache.PackFileCacheStrategy` logs
@@ -3218,9 +3309,9 @@ var init_basic = __esm({
3218
3309
  exportsPresence: "error"
3219
3310
  }
3220
3311
  });
3221
- const isMinimize = isProd4 && config.output.minify !== false;
3312
+ const isMinimize = isProd5 && config.output.minify !== false;
3222
3313
  chain.optimization.minimize(isMinimize);
3223
- const usingHMR = (0, import_shared25.isUsingHMR)(config, { target, isProd: isProd4 });
3314
+ const usingHMR = (0, import_shared25.isUsingHMR)(config, { target, isProd: isProd5 });
3224
3315
  if (usingHMR) {
3225
3316
  chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
3226
3317
  }
@@ -3402,7 +3493,7 @@ async function applyCSSRule({
3402
3493
  rule,
3403
3494
  config,
3404
3495
  context,
3405
- utils: { target, isProd: isProd4, CHAIN_ID: CHAIN_ID3 },
3496
+ utils: { target, isProd: isProd5, CHAIN_ID: CHAIN_ID3 },
3406
3497
  importLoaders = 1
3407
3498
  }) {
3408
3499
  const browserslist = await (0, import_shared28.getBrowserslistWithDefault)(
@@ -3411,7 +3502,7 @@ async function applyCSSRule({
3411
3502
  target
3412
3503
  );
3413
3504
  const enableExtractCSS = isUseCssExtract(config, target);
3414
- const localIdentName = getCSSModulesLocalIdentName(config, isProd4);
3505
+ const localIdentName = getCSSModulesLocalIdentName(config, isProd5);
3415
3506
  const cssLoaderOptions = getCSSLoaderOptions({
3416
3507
  config,
3417
3508
  importLoaders,
@@ -3422,9 +3513,9 @@ async function applyCSSRule({
3422
3513
  if (enableExtractCSS) {
3423
3514
  rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions).end();
3424
3515
  } else {
3425
- const styleLoaderOptions = (0, import_shared28.mergeChainedOptions)({
3426
- defaults: {},
3427
- options: config.tools.styleLoader
3516
+ const styleLoaderOptions = (0, import_shared28.reduceConfigs)({
3517
+ initial: {},
3518
+ config: config.tools.styleLoader
3428
3519
  });
3429
3520
  rule.use(CHAIN_ID3.USE.STYLE).loader(getCompiledPath("style-loader")).options(styleLoaderOptions).end();
3430
3521
  }
@@ -3454,8 +3545,8 @@ var init_css = __esm({
3454
3545
  init_pluginHelper();
3455
3546
  enableNativeCss = (config) => !config.output.injectStyles;
3456
3547
  isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
3457
- getCSSModulesLocalIdentName = (config, isProd4) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3458
- (isProd4 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
3548
+ getCSSModulesLocalIdentName = (config, isProd5) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3549
+ (isProd5 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
3459
3550
  normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
3460
3551
  if (options.modules && exportOnlyLocals) {
3461
3552
  let { modules } = options;
@@ -3492,12 +3583,12 @@ var init_css = __esm({
3492
3583
  });
3493
3584
  if (!hasAutoprefixer) {
3494
3585
  const { default: autoprefixer } = await import("@rsbuild/shared/autoprefixer");
3495
- const autoprefixerOptions = (0, import_shared28.mergeChainedOptions)({
3496
- defaults: {
3586
+ const autoprefixerOptions = (0, import_shared28.reduceConfigs)({
3587
+ initial: {
3497
3588
  flexbox: "no-2009",
3498
3589
  overrideBrowserslist: browserslist
3499
3590
  },
3500
- options: config.tools.autoprefixer
3591
+ config: config.tools.autoprefixer
3501
3592
  });
3502
3593
  pluginObjects.push(autoprefixer(autoprefixerOptions));
3503
3594
  }
@@ -3532,10 +3623,10 @@ var init_css = __esm({
3532
3623
  },
3533
3624
  sourceMap: config.output.sourceMap.css
3534
3625
  };
3535
- const mergedConfig = (0, import_shared28.mergeChainedOptions)({
3536
- defaults: defaultPostcssConfig,
3537
- options: config.tools.postcss,
3538
- utils
3626
+ const mergedConfig = (0, import_shared28.reduceConfigsWithContext)({
3627
+ initial: defaultPostcssConfig,
3628
+ config: config.tools.postcss,
3629
+ ctx: utils
3539
3630
  });
3540
3631
  if (extraPlugins.length) {
3541
3632
  mergedConfig?.postcssOptions?.plugins.push(...extraPlugins);
@@ -3559,9 +3650,9 @@ var init_css = __esm({
3559
3650
  },
3560
3651
  sourceMap: config.output.sourceMap.css
3561
3652
  };
3562
- const mergedCssLoaderOptions = (0, import_shared28.mergeChainedOptions)({
3563
- defaults: defaultOptions2,
3564
- options: config.tools.cssLoader,
3653
+ const mergedCssLoaderOptions = (0, import_shared28.reduceConfigs)({
3654
+ initial: defaultOptions2,
3655
+ config: config.tools.cssLoader,
3565
3656
  mergeFn: import_shared28.deepmerge
3566
3657
  });
3567
3658
  const cssLoaderOptions = normalizeCssLoaderOptions(
@@ -3602,13 +3693,13 @@ __export(output_exports, {
3602
3693
  pluginOutput: () => pluginOutput
3603
3694
  });
3604
3695
  function getPublicPath({
3605
- isProd: isProd4,
3696
+ isProd: isProd5,
3606
3697
  config,
3607
3698
  context
3608
3699
  }) {
3609
3700
  const { dev, output } = config;
3610
3701
  let publicPath = import_shared29.DEFAULT_ASSET_PREFIX;
3611
- if (isProd4) {
3702
+ if (isProd5) {
3612
3703
  if (typeof output.assetPrefix === "string") {
3613
3704
  publicPath = output.assetPrefix;
3614
3705
  }
@@ -3616,9 +3707,9 @@ function getPublicPath({
3616
3707
  publicPath = dev.assetPrefix;
3617
3708
  } else if (dev.assetPrefix === true) {
3618
3709
  const protocol = context.devServer?.https ? "https" : "http";
3619
- const hostname = context.devServer?.hostname || import_shared29.DEFAULT_DEV_HOST;
3620
- const port = context.devServer?.port || import_shared29.DEFAULT_PORT;
3621
- 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) {
3622
3713
  const localHostname = "localhost";
3623
3714
  publicPath = `${protocol}://${localHostname}:${port}/`;
3624
3715
  } else {
@@ -3634,6 +3725,7 @@ var init_output = __esm({
3634
3725
  import_node_path15 = require("path");
3635
3726
  import_shared29 = require("@rsbuild/shared");
3636
3727
  import_core5 = require("@rspack/core");
3728
+ init_constants();
3637
3729
  init_helpers();
3638
3730
  init_pluginHelper();
3639
3731
  init_css();
@@ -3641,20 +3733,34 @@ var init_output = __esm({
3641
3733
  name: "rsbuild:output",
3642
3734
  setup(api) {
3643
3735
  api.modifyBundlerChain(
3644
- async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd4, isServer, isServiceWorker }) => {
3736
+ async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd5, isServer, isServiceWorker }) => {
3645
3737
  const config = api.getNormalizedConfig();
3646
3738
  const publicPath = getPublicPath({
3647
3739
  config,
3648
- isProd: isProd4,
3740
+ isProd: isProd5,
3649
3741
  context: api.context
3650
3742
  });
3651
3743
  const jsPath = (0, import_shared29.getDistPath)(config, "js");
3652
3744
  const jsAsyncPath = (0, import_shared29.getDistPath)(config, "jsAsync");
3653
- const jsFilename = (0, import_shared29.getFilename)(config, "js", isProd4);
3654
- 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");
3745
+ const jsFilename = (0, import_shared29.getFilename)(config, "js", isProd5);
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");
3655
3758
  if (isServer) {
3656
3759
  const serverPath = (0, import_shared29.getDistPath)(config, "server");
3657
- chain.output.path(import_node_path15.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").libraryTarget("commonjs2");
3760
+ chain.output.path(import_node_path15.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3761
+ ...chain.output.get("library") || {},
3762
+ type: "commonjs2"
3763
+ });
3658
3764
  }
3659
3765
  if (isServiceWorker) {
3660
3766
  const workerPath = (0, import_shared29.getDistPath)(config, "worker");
@@ -3669,7 +3775,7 @@ var init_output = __esm({
3669
3775
  if (isUseCssExtract(config, target)) {
3670
3776
  const extractPluginOptions = config.tools.cssExtract.pluginOptions;
3671
3777
  const cssPath = (0, import_shared29.getDistPath)(config, "css");
3672
- const cssFilename = (0, import_shared29.getFilename)(config, "css", isProd4);
3778
+ const cssFilename = (0, import_shared29.getFilename)(config, "css", isProd5);
3673
3779
  const cssAsyncPath = (0, import_shared29.getDistPath)(config, "cssAsync");
3674
3780
  chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
3675
3781
  {
@@ -3719,10 +3825,10 @@ function applyAlias({
3719
3825
  if (!alias) {
3720
3826
  return;
3721
3827
  }
3722
- const mergedAlias = (0, import_shared30.mergeChainedOptions)({
3723
- defaults: {},
3724
- options: alias,
3725
- utils: { target }
3828
+ const mergedAlias = (0, import_shared30.reduceConfigsWithContext)({
3829
+ initial: {},
3830
+ config: alias,
3831
+ ctx: { target }
3726
3832
  });
3727
3833
  for (const name of Object.keys(mergedAlias)) {
3728
3834
  const values = (0, import_shared30.castArray)(mergedAlias[name]);
@@ -4020,6 +4126,7 @@ var init_asset = __esm({
4020
4126
  "use strict";
4021
4127
  import_node_path18 = __toESM(require("path"));
4022
4128
  import_shared34 = require("@rsbuild/shared");
4129
+ init_constants();
4023
4130
  chainStaticAssetRule = ({
4024
4131
  emit,
4025
4132
  rule,
@@ -4044,12 +4151,12 @@ var init_asset = __esm({
4044
4151
  pluginAsset = () => ({
4045
4152
  name: "rsbuild:asset",
4046
4153
  setup(api) {
4047
- api.modifyBundlerChain((chain, { isProd: isProd4, target }) => {
4154
+ api.modifyBundlerChain((chain, { isProd: isProd5, target }) => {
4048
4155
  const config = api.getNormalizedConfig();
4049
4156
  const createAssetRule = (assetType, exts, emit2) => {
4050
4157
  const regExp = getRegExpForExts(exts);
4051
4158
  const distDir = (0, import_shared34.getDistPath)(config, assetType);
4052
- const filename = (0, import_shared34.getFilename)(config, assetType, isProd4);
4159
+ const filename = (0, import_shared34.getFilename)(config, assetType, isProd5);
4053
4160
  const { dataUriLimit } = config.output;
4054
4161
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
4055
4162
  const rule = chain.module.rule(assetType).test(regExp);
@@ -4062,14 +4169,14 @@ var init_asset = __esm({
4062
4169
  });
4063
4170
  };
4064
4171
  const emit = config.output.emitAssets({ target });
4065
- createAssetRule("image", import_shared34.IMAGE_EXTENSIONS, emit);
4172
+ createAssetRule("image", IMAGE_EXTENSIONS, emit);
4066
4173
  createAssetRule("svg", ["svg"], emit);
4067
4174
  createAssetRule(
4068
4175
  "media",
4069
- [...import_shared34.VIDEO_EXTENSIONS, ...import_shared34.AUDIO_EXTENSIONS],
4176
+ [...VIDEO_EXTENSIONS, ...AUDIO_EXTENSIONS],
4070
4177
  emit
4071
4178
  );
4072
- createAssetRule("font", import_shared34.FONT_EXTENSIONS, emit);
4179
+ createAssetRule("font", FONT_EXTENSIONS, emit);
4073
4180
  });
4074
4181
  }
4075
4182
  });
@@ -4127,9 +4234,9 @@ var init_minimize = __esm({
4127
4234
  }
4128
4235
  return options;
4129
4236
  };
4130
- parseMinifyOptions = (config, isProd4 = true) => {
4237
+ parseMinifyOptions = (config, isProd5 = true) => {
4131
4238
  const minify = config.output.minify;
4132
- if (minify === false || !isProd4) {
4239
+ if (minify === false || !isProd5) {
4133
4240
  return {
4134
4241
  minifyJs: false,
4135
4242
  minifyCss: false,
@@ -4161,9 +4268,9 @@ var init_minimize = __esm({
4161
4268
  if (api.context.bundlerType === "webpack") {
4162
4269
  return;
4163
4270
  }
4164
- api.modifyBundlerChain(async (chain, { isProd: isProd4 }) => {
4271
+ api.modifyBundlerChain(async (chain, { isProd: isProd5 }) => {
4165
4272
  const config = api.getNormalizedConfig();
4166
- const isMinimize = isProd4 && config.output.minify !== false;
4273
+ const isMinimize = isProd5 && config.output.minify !== false;
4167
4274
  if (!isMinimize) {
4168
4275
  return;
4169
4276
  }
@@ -4366,13 +4473,18 @@ var init_HtmlBasicPlugin = __esm({
4366
4473
  addTitleTag(headTags, data.plugin.options?.title);
4367
4474
  }
4368
4475
  addFavicon(headTags, favicon);
4369
- const result = await this.modifyTagsFn({
4476
+ const tags = {
4370
4477
  headTags: headTags.map(formatBasicTag),
4371
4478
  bodyTags: bodyTags.map(formatBasicTag)
4372
- });
4479
+ };
4480
+ const modified = this.modifyTagsFn ? await this.modifyTagsFn(tags, {
4481
+ compilation,
4482
+ assetPrefix: data.publicPath,
4483
+ filename: data.outputName
4484
+ }) : tags;
4373
4485
  Object.assign(data, {
4374
- headTags: result.headTags.map(fromBasicTag),
4375
- bodyTags: result.bodyTags.map(fromBasicTag)
4486
+ headTags: modified.headTags.map(fromBasicTag),
4487
+ bodyTags: modified.bodyTags.map(fromBasicTag)
4376
4488
  });
4377
4489
  if (tagConfig) {
4378
4490
  const hash = compilation.hash ?? "";
@@ -4497,8 +4609,8 @@ function getTerserMinifyOptions(config) {
4497
4609
  const finalOptions = applyRemoveConsole(options, config);
4498
4610
  return finalOptions;
4499
4611
  }
4500
- async function getHtmlMinifyOptions(isProd4, config) {
4501
- if (!isProd4 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4612
+ async function getHtmlMinifyOptions(isProd5, config) {
4613
+ if (!isProd5 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4502
4614
  return false;
4503
4615
  }
4504
4616
  const minifyJS = getTerserMinifyOptions(config);
@@ -4519,29 +4631,25 @@ async function getHtmlMinifyOptions(isProd4, config) {
4519
4631
  return typeof htmlMinifyOptions === "object" ? (0, import_shared38.deepmerge)(htmlMinifyDefaultOptions, htmlMinifyOptions) : htmlMinifyDefaultOptions;
4520
4632
  }
4521
4633
  function getTitle(entryName, config) {
4522
- return (0, import_shared38.mergeChainedOptions)({
4523
- defaults: "",
4524
- options: config.html.title,
4525
- utils: { entryName },
4526
- useObjectParam: true
4634
+ return (0, import_shared38.reduceConfigsMergeContext)({
4635
+ initial: "",
4636
+ config: config.html.title,
4637
+ ctx: { entryName }
4527
4638
  });
4528
4639
  }
4529
4640
  function getInject(entryName, config) {
4530
- return (0, import_shared38.mergeChainedOptions)({
4531
- defaults: "head",
4532
- options: config.html.inject,
4533
- utils: { entryName },
4534
- useObjectParam: true,
4535
- isFalsy: import_shared38.isNil
4641
+ return (0, import_shared38.reduceConfigsMergeContext)({
4642
+ initial: "head",
4643
+ config: config.html.inject,
4644
+ ctx: { entryName }
4536
4645
  });
4537
4646
  }
4538
4647
  async function getTemplate(entryName, config, rootPath) {
4539
4648
  const DEFAULT_TEMPLATE = import_node_path20.default.resolve(STATIC_PATH, "template.html");
4540
- const templatePath = (0, import_shared38.mergeChainedOptions)({
4541
- defaults: DEFAULT_TEMPLATE,
4542
- options: config.html.template,
4543
- utils: { entryName },
4544
- useObjectParam: true
4649
+ const templatePath = (0, import_shared38.reduceConfigsMergeContext)({
4650
+ initial: DEFAULT_TEMPLATE,
4651
+ config: config.html.template,
4652
+ ctx: { entryName }
4545
4653
  });
4546
4654
  if (templatePath === DEFAULT_TEMPLATE) {
4547
4655
  return {
@@ -4566,19 +4674,17 @@ async function getTemplate(entryName, config, rootPath) {
4566
4674
  };
4567
4675
  }
4568
4676
  function getFavicon(entryName, config) {
4569
- return (0, import_shared38.mergeChainedOptions)({
4570
- defaults: "",
4571
- options: config.html.favicon,
4572
- utils: { entryName },
4573
- useObjectParam: true
4677
+ return (0, import_shared38.reduceConfigsMergeContext)({
4678
+ initial: "",
4679
+ config: config.html.favicon,
4680
+ ctx: { entryName }
4574
4681
  });
4575
4682
  }
4576
4683
  function getMetaTags(entryName, config, templateContent) {
4577
- const metaTags = (0, import_shared38.mergeChainedOptions)({
4578
- defaults: {},
4579
- options: config.html.meta,
4580
- utils: { entryName },
4581
- useObjectParam: true
4684
+ const metaTags = (0, import_shared38.reduceConfigsMergeContext)({
4685
+ initial: {},
4686
+ config: config.html.meta,
4687
+ ctx: { entryName }
4582
4688
  });
4583
4689
  if (templateContent && metaTags.charset) {
4584
4690
  const charsetRegExp = /<meta[^>]+charset=["'][^>]*>/i;
@@ -4603,10 +4709,10 @@ function getTemplateParameters(entryName, config, assetPrefix) {
4603
4709
  options: pluginOptions
4604
4710
  }
4605
4711
  };
4606
- return (0, import_shared38.mergeChainedOptions)({
4607
- defaults: defaultOptions2,
4608
- options: templateParameters,
4609
- utils: { entryName }
4712
+ return (0, import_shared38.reduceConfigsWithContext)({
4713
+ initial: defaultOptions2,
4714
+ config: templateParameters,
4715
+ ctx: { entryName }
4610
4716
  });
4611
4717
  };
4612
4718
  }
@@ -4655,12 +4761,12 @@ var init_html = __esm({
4655
4761
  name: "rsbuild:html",
4656
4762
  setup(api) {
4657
4763
  api.modifyBundlerChain(
4658
- async (chain, { HtmlPlugin, isProd: isProd4, CHAIN_ID: CHAIN_ID3, target }) => {
4764
+ async (chain, { HtmlPlugin, isProd: isProd5, CHAIN_ID: CHAIN_ID3, target }) => {
4659
4765
  const config = api.getNormalizedConfig();
4660
4766
  if ((0, import_shared38.isHtmlDisabled)(config, target)) {
4661
4767
  return;
4662
4768
  }
4663
- const minify = await getHtmlMinifyOptions(isProd4, config);
4769
+ const minify = await getHtmlMinifyOptions(isProd5, config);
4664
4770
  const assetPrefix = getPublicPathFromChain(chain, false);
4665
4771
  const entries = chain.entryPoints.entries() || {};
4666
4772
  const entryNames = Object.keys(entries);
@@ -4669,11 +4775,7 @@ var init_html = __esm({
4669
4775
  const finalOptions = await Promise.all(
4670
4776
  entryNames.map(async (entryName) => {
4671
4777
  const entryValue = entries[entryName].values();
4672
- const chunks = getChunks(
4673
- entryName,
4674
- // EntryDescription type is different between webpack and Rspack
4675
- entryValue
4676
- );
4778
+ const chunks = getChunks(entryName, entryValue);
4677
4779
  const inject = getInject(entryName, config);
4678
4780
  const filename = htmlPaths[entryName];
4679
4781
  const { templatePath, templateContent } = await getTemplate(
@@ -4719,13 +4821,10 @@ var init_html = __esm({
4719
4821
  pluginOptions.favicon = favicon;
4720
4822
  }
4721
4823
  }
4722
- const finalOptions2 = (0, import_shared38.mergeChainedOptions)({
4723
- defaults: pluginOptions,
4724
- options: typeof config.tools.htmlPlugin === "boolean" ? {} : config.tools.htmlPlugin,
4725
- utils: {
4726
- entryName,
4727
- entryValue
4728
- }
4824
+ const finalOptions2 = (0, import_shared38.reduceConfigsWithContext)({
4825
+ initial: pluginOptions,
4826
+ config: typeof config.tools.htmlPlugin === "boolean" ? {} : config.tools.htmlPlugin,
4827
+ ctx: { entryName, entryValue }
4729
4828
  });
4730
4829
  return finalOptions2;
4731
4830
  })
@@ -4750,52 +4849,21 @@ var init_html = __esm({
4750
4849
  }
4751
4850
  }
4752
4851
  );
4753
- api.onAfterCreateCompiler(({ compiler }) => {
4754
- const { nonce } = api.getNormalizedConfig().security;
4755
- if (!nonce) {
4756
- return;
4757
- }
4758
- (0, import_shared38.applyToCompiler)(compiler, (compiler2) => {
4759
- const { plugins } = compiler2.options;
4760
- const hasHTML = plugins.some(
4761
- (plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
4762
- );
4763
- if (!hasHTML) {
4764
- return;
4765
- }
4766
- const injectCode = (0, import_shared38.createVirtualModule)(
4767
- `__webpack_nonce__ = "${nonce}";`
4768
- );
4769
- new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
4770
- name: void 0
4771
- }).apply(compiler2);
4772
- });
4773
- });
4774
4852
  api.modifyHTMLTags({
4775
4853
  // ensure `crossorigin` and `nonce` can be applied to all tags
4776
4854
  order: "post",
4777
4855
  handler: ({ headTags, bodyTags }) => {
4778
4856
  const config = api.getNormalizedConfig();
4779
4857
  const { crossorigin } = config.html;
4780
- const { nonce } = config.security;
4781
4858
  const allTags = [...headTags, ...bodyTags];
4782
4859
  if (crossorigin) {
4783
4860
  const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
4784
4861
  for (const tag of allTags) {
4785
4862
  if (tag.tag === "script" && tag.attrs?.src || tag.tag === "link" && tag.attrs?.rel === "stylesheet") {
4786
- tag.attrs ||= {};
4787
4863
  tag.attrs.crossorigin ??= formattedCrossorigin;
4788
4864
  }
4789
4865
  }
4790
4866
  }
4791
- if (nonce) {
4792
- for (const tag of allTags) {
4793
- if (tag.tag === "script" || tag.tag === "style") {
4794
- tag.attrs ??= {};
4795
- tag.attrs.nonce = nonce;
4796
- }
4797
- }
4798
- }
4799
4867
  return { headTags, bodyTags };
4800
4868
  }
4801
4869
  });
@@ -5096,9 +5164,9 @@ var init_swc = __esm({
5096
5164
  await applyCoreJs(swcConfig, chain, polyfillMode);
5097
5165
  }
5098
5166
  }
5099
- const mergedSwcConfig = (0, import_shared42.mergeChainedOptions)({
5100
- defaults: swcConfig,
5101
- options: config.tools.swc,
5167
+ const mergedSwcConfig = (0, import_shared42.reduceConfigs)({
5168
+ initial: swcConfig,
5169
+ config: config.tools.swc,
5102
5170
  mergeFn: import_shared42.deepmerge
5103
5171
  });
5104
5172
  rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
@@ -5342,10 +5410,7 @@ var init_splitChunks = __esm({
5342
5410
  rootPath: api.context.rootPath,
5343
5411
  polyfill: config.output.polyfill
5344
5412
  });
5345
- chain.optimization.splitChunks(
5346
- // @ts-expect-error splitChunks type mismatch
5347
- splitChunksOptions
5348
- );
5413
+ chain.optimization.splitChunks(splitChunksOptions);
5349
5414
  }
5350
5415
  );
5351
5416
  }
@@ -5353,12 +5418,13 @@ var init_splitChunks = __esm({
5353
5418
  }
5354
5419
  });
5355
5420
 
5356
- // src/plugins/startUrl.ts
5357
- var startUrl_exports = {};
5358
- __export(startUrl_exports, {
5421
+ // src/plugins/open.ts
5422
+ var open_exports = {};
5423
+ __export(open_exports, {
5359
5424
  openBrowser: () => openBrowser,
5360
- pluginStartUrl: () => pluginStartUrl,
5361
- replacePlaceholder: () => replacePlaceholder
5425
+ pluginOpen: () => pluginOpen,
5426
+ replacePlaceholder: () => replacePlaceholder,
5427
+ resolveUrl: () => resolveUrl
5362
5428
  });
5363
5429
  async function openBrowser(url2) {
5364
5430
  const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
@@ -5392,30 +5458,45 @@ async function openBrowser(url2) {
5392
5458
  return false;
5393
5459
  }
5394
5460
  }
5395
- function pluginStartUrl() {
5461
+ function resolveUrl(str, base) {
5462
+ if ((0, import_shared44.canParse)(str)) {
5463
+ return str;
5464
+ }
5465
+ try {
5466
+ const url2 = new URL(str, base);
5467
+ return url2.href;
5468
+ } catch (e) {
5469
+ throw new Error(
5470
+ "[rsbuild:open]: Invalid input: not a valid URL or pathname"
5471
+ );
5472
+ }
5473
+ }
5474
+ function pluginOpen() {
5396
5475
  return {
5397
- name: "rsbuild:start-url",
5476
+ name: "rsbuild:open",
5398
5477
  setup(api) {
5399
5478
  const onStartServer = async (params) => {
5400
5479
  const { port, routes } = params;
5401
5480
  const config = api.getNormalizedConfig();
5402
- const { startUrl, beforeStartUrl } = config.dev;
5481
+ const { beforeStartUrl } = config.dev;
5482
+ const open = config.server.open || config.dev.startUrl;
5403
5483
  const { https } = api.context.devServer || {};
5404
5484
  const isCodesandbox = process.env.CSB === "true";
5405
- const shouldOpen = Boolean(startUrl) && !isCodesandbox;
5485
+ const shouldOpen = Boolean(open) && !isCodesandbox;
5406
5486
  if (!shouldOpen) {
5407
5487
  return;
5408
5488
  }
5409
5489
  const urls = [];
5410
- if (startUrl === true || !startUrl) {
5411
- const protocol = https ? "https" : "http";
5490
+ const protocol = https ? "https" : "http";
5491
+ const baseUrl = `${protocol}://localhost:${port}`;
5492
+ if (open === true || !open) {
5412
5493
  if (routes.length) {
5413
- urls.push(`${protocol}://localhost:${port}${routes[0].pathname}`);
5494
+ urls.push(`${baseUrl}${routes[0].pathname}`);
5414
5495
  }
5415
5496
  } else {
5416
5497
  urls.push(
5417
- ...(0, import_shared44.castArray)(startUrl).map(
5418
- (item) => replacePlaceholder(item, port)
5498
+ ...(0, import_shared44.castArray)(open).map(
5499
+ (item) => resolveUrl(replacePlaceholder(item, port), baseUrl)
5419
5500
  )
5420
5501
  );
5421
5502
  }
@@ -5441,8 +5522,8 @@ function pluginStartUrl() {
5441
5522
  };
5442
5523
  }
5443
5524
  var import_node_child_process, import_node_util, import_shared44, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs;
5444
- var init_startUrl = __esm({
5445
- "src/plugins/startUrl.ts"() {
5525
+ var init_open = __esm({
5526
+ "src/plugins/open.ts"() {
5446
5527
  "use strict";
5447
5528
  import_node_child_process = require("child_process");
5448
5529
  import_node_util = require("util");
@@ -5850,16 +5931,16 @@ function determineAsValue({
5850
5931
  if (["css"].includes(extension)) {
5851
5932
  return "style";
5852
5933
  }
5853
- if (import_shared49.IMAGE_EXTENSIONS.includes(extension)) {
5934
+ if (IMAGE_EXTENSIONS.includes(extension)) {
5854
5935
  return "image";
5855
5936
  }
5856
- if (import_shared49.VIDEO_EXTENSIONS.includes(extension)) {
5937
+ if (VIDEO_EXTENSIONS.includes(extension)) {
5857
5938
  return "video";
5858
5939
  }
5859
- if (import_shared49.AUDIO_EXTENSIONS.includes(extension)) {
5940
+ if (AUDIO_EXTENSIONS.includes(extension)) {
5860
5941
  return "audio";
5861
5942
  }
5862
- if (import_shared49.FONT_EXTENSIONS.includes(extension)) {
5943
+ if (FONT_EXTENSIONS.includes(extension)) {
5863
5944
  return "font";
5864
5945
  }
5865
5946
  if (["vtt"].includes(extension)) {
@@ -5867,13 +5948,13 @@ function determineAsValue({
5867
5948
  }
5868
5949
  return "script";
5869
5950
  }
5870
- var import_node_path25, import_node_url3, import_shared49;
5951
+ var import_node_path25, import_node_url3;
5871
5952
  var init_determineAsValue = __esm({
5872
5953
  "src/rspack/preload/helpers/determineAsValue.ts"() {
5873
5954
  "use strict";
5874
5955
  import_node_path25 = __toESM(require("path"));
5875
5956
  import_node_url3 = require("url");
5876
- import_shared49 = require("@rsbuild/shared");
5957
+ init_constants();
5877
5958
  }
5878
5959
  });
5879
5960
 
@@ -5981,10 +6062,10 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
5981
6062
  );
5982
6063
  const sortedFilteredFiles = filteredFiles.sort();
5983
6064
  const links = [];
5984
- const publicPath = (0, import_shared50.getPublicPathFromCompiler)(compilation.compiler);
6065
+ const publicPath = (0, import_shared49.getPublicPathFromCompiler)(compilation.compiler);
5985
6066
  const { crossOriginLoading } = compilation.compiler.options.output;
5986
6067
  for (const file of sortedFilteredFiles) {
5987
- const href = (0, import_shared50.withPublicPath)(file, publicPath);
6068
+ const href = (0, import_shared49.withPublicPath)(file, publicPath);
5988
6069
  const attributes = {
5989
6070
  href,
5990
6071
  rel: type
@@ -6012,11 +6093,11 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
6012
6093
  }
6013
6094
  return links;
6014
6095
  }
6015
- var import_shared50, defaultOptions, HtmlPreloadOrPrefetchPlugin;
6096
+ var import_shared49, defaultOptions, HtmlPreloadOrPrefetchPlugin;
6016
6097
  var init_HtmlPreloadOrPrefetchPlugin = __esm({
6017
6098
  "src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
6018
6099
  "use strict";
6019
- import_shared50 = require("@rsbuild/shared");
6100
+ import_shared49 = require("@rsbuild/shared");
6020
6101
  init_pluginHelper();
6021
6102
  init_helpers2();
6022
6103
  defaultOptions = {
@@ -6038,7 +6119,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6038
6119
  apply(compiler) {
6039
6120
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
6040
6121
  getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
6041
- `HTML${(0, import_shared50.upperFirst)(this.type)}Plugin`,
6122
+ `HTML${(0, import_shared49.upperFirst)(this.type)}Plugin`,
6042
6123
  (htmlPluginData) => {
6043
6124
  this.resourceHints = generateLinks(
6044
6125
  this.options,
@@ -6051,7 +6132,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6051
6132
  }
6052
6133
  );
6053
6134
  getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
6054
- `HTML${(0, import_shared50.upperFirst)(this.type)}Plugin`,
6135
+ `HTML${(0, import_shared49.upperFirst)(this.type)}Plugin`,
6055
6136
  (htmlPluginData) => {
6056
6137
  if (this.resourceHints) {
6057
6138
  htmlPluginData.assetTags.styles = [
@@ -6076,11 +6157,11 @@ var resourceHints_exports = {};
6076
6157
  __export(resourceHints_exports, {
6077
6158
  pluginResourceHints: () => pluginResourceHints
6078
6159
  });
6079
- var import_shared51, generateLinks2, pluginResourceHints;
6160
+ var import_shared50, generateLinks2, pluginResourceHints;
6080
6161
  var init_resourceHints = __esm({
6081
6162
  "src/plugins/resourceHints.ts"() {
6082
6163
  "use strict";
6083
- import_shared51 = require("@rsbuild/shared");
6164
+ import_shared50 = require("@rsbuild/shared");
6084
6165
  generateLinks2 = (options, rel) => options.map((option) => ({
6085
6166
  tag: "link",
6086
6167
  attrs: {
@@ -6115,7 +6196,7 @@ var init_resourceHints = __esm({
6115
6196
  const {
6116
6197
  performance: { preload, prefetch }
6117
6198
  } = config;
6118
- if ((0, import_shared51.isHtmlDisabled)(config, target)) {
6199
+ if ((0, import_shared50.isHtmlDisabled)(config, target)) {
6119
6200
  return;
6120
6201
  }
6121
6202
  const HTMLCount = chain.entryPoints.values().length;
@@ -6178,12 +6259,12 @@ var server_exports = {};
6178
6259
  __export(server_exports, {
6179
6260
  pluginServer: () => pluginServer
6180
6261
  });
6181
- var import_node_path26, import_shared52, pluginServer;
6262
+ var import_node_path26, import_shared51, pluginServer;
6182
6263
  var init_server = __esm({
6183
6264
  "src/plugins/server.ts"() {
6184
6265
  "use strict";
6185
6266
  import_node_path26 = require("path");
6186
- import_shared52 = require("@rsbuild/shared");
6267
+ import_shared51 = require("@rsbuild/shared");
6187
6268
  pluginServer = () => ({
6188
6269
  name: "rsbuild:server",
6189
6270
  setup(api) {
@@ -6195,11 +6276,11 @@ var init_server = __esm({
6195
6276
  return;
6196
6277
  }
6197
6278
  const publicDir = (0, import_node_path26.isAbsolute)(name) ? name : (0, import_node_path26.join)(api.context.rootPath, name);
6198
- if (!import_shared52.fse.existsSync(publicDir)) {
6279
+ if (!import_shared51.fse.existsSync(publicDir)) {
6199
6280
  return;
6200
6281
  }
6201
6282
  try {
6202
- await import_shared52.fse.copy(publicDir, api.context.distPath, {
6283
+ await import_shared51.fse.copy(publicDir, api.context.distPath, {
6203
6284
  // dereference symlinks
6204
6285
  dereference: true
6205
6286
  });
@@ -6313,7 +6394,6 @@ var init_manifest = __esm({
6313
6394
  name: "rsbuild:manifest",
6314
6395
  setup(api) {
6315
6396
  api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
6316
- const htmlPaths = api.getHTMLPaths();
6317
6397
  const {
6318
6398
  output: { manifest }
6319
6399
  } = api.getNormalizedConfig();
@@ -6322,6 +6402,7 @@ var init_manifest = __esm({
6322
6402
  }
6323
6403
  const fileName = typeof manifest === "string" ? manifest : "manifest.json";
6324
6404
  const { RspackManifestPlugin } = await import("../compiled/rspack-manifest-plugin/index.js");
6405
+ const htmlPaths = api.getHTMLPaths();
6325
6406
  chain.plugin(CHAIN_ID3.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
6326
6407
  {
6327
6408
  fileName,
@@ -6366,18 +6447,18 @@ function pluginModuleFederation() {
6366
6447
  chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
6367
6448
  }
6368
6449
  const publicPath = chain.output.get("publicPath");
6369
- if (publicPath === import_shared53.DEFAULT_ASSET_PREFIX) {
6450
+ if (publicPath === import_shared52.DEFAULT_ASSET_PREFIX) {
6370
6451
  chain.output.set("publicPath", "auto");
6371
6452
  }
6372
6453
  });
6373
6454
  }
6374
6455
  };
6375
6456
  }
6376
- var import_shared53, import_core8, PatchSplitChunksPlugin;
6457
+ var import_shared52, import_core8, PatchSplitChunksPlugin;
6377
6458
  var init_moduleFederation = __esm({
6378
6459
  "src/plugins/moduleFederation.ts"() {
6379
6460
  "use strict";
6380
- import_shared53 = require("@rsbuild/shared");
6461
+ import_shared52 = require("@rsbuild/shared");
6381
6462
  import_core8 = require("@rspack/core");
6382
6463
  PatchSplitChunksPlugin = class {
6383
6464
  constructor(name) {
@@ -6445,14 +6526,14 @@ __export(rspackProfile_exports, {
6445
6526
  pluginRspackProfile: () => pluginRspackProfile,
6446
6527
  stopProfiler: () => stopProfiler
6447
6528
  });
6448
- var import_node_inspector, import_node_path27, import_shared54, import_shared55, import_core9, stopProfiler, pluginRspackProfile;
6529
+ var import_node_inspector, import_node_path27, import_shared53, import_shared54, import_core9, stopProfiler, pluginRspackProfile;
6449
6530
  var init_rspackProfile = __esm({
6450
6531
  "src/plugins/rspackProfile.ts"() {
6451
6532
  "use strict";
6452
6533
  import_node_inspector = __toESM(require("inspector"));
6453
6534
  import_node_path27 = __toESM(require("path"));
6535
+ import_shared53 = require("@rsbuild/shared");
6454
6536
  import_shared54 = require("@rsbuild/shared");
6455
- import_shared55 = require("@rsbuild/shared");
6456
6537
  import_core9 = require("@rspack/core");
6457
6538
  stopProfiler = (output, profileSession) => {
6458
6539
  if (!profileSession) {
@@ -6460,10 +6541,10 @@ var init_rspackProfile = __esm({
6460
6541
  }
6461
6542
  profileSession.post("Profiler.stop", (error, param) => {
6462
6543
  if (error) {
6463
- import_shared55.logger.error("Failed to generate JS CPU profile:", error);
6544
+ import_shared54.logger.error("Failed to generate JS CPU profile:", error);
6464
6545
  return;
6465
6546
  }
6466
- import_shared54.fse.writeFileSync(output, JSON.stringify(param.profile));
6547
+ import_shared53.fse.writeFileSync(output, JSON.stringify(param.profile));
6467
6548
  });
6468
6549
  };
6469
6550
  pluginRspackProfile = () => ({
@@ -6489,7 +6570,7 @@ var init_rspackProfile = __esm({
6489
6570
  const cpuProfilePath = import_node_path27.default.join(profileDir, "jscpuprofile.json");
6490
6571
  const loggingFilePath = import_node_path27.default.join(profileDir, "logging.json");
6491
6572
  const onStart = () => {
6492
- import_shared54.fse.ensureDirSync(profileDir);
6573
+ import_shared53.fse.ensureDirSync(profileDir);
6493
6574
  if (enableProfileTrace) {
6494
6575
  import_core9.rspack.experimental_registerGlobalTrace(
6495
6576
  "trace",
@@ -6513,7 +6594,7 @@ var init_rspackProfile = __esm({
6513
6594
  logging: "verbose",
6514
6595
  loggingTrace: true
6515
6596
  });
6516
- import_shared54.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
6597
+ import_shared53.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
6517
6598
  }
6518
6599
  });
6519
6600
  api.onExit(() => {
@@ -6521,7 +6602,7 @@ var init_rspackProfile = __esm({
6521
6602
  import_core9.rspack.experimental_cleanupGlobalTrace();
6522
6603
  }
6523
6604
  stopProfiler(cpuProfilePath, profileSession);
6524
- import_shared55.logger.info(`Saved Rspack profile file to ${profileDir}`);
6605
+ import_shared54.logger.info(`Saved Rspack profile file to ${profileDir}`);
6525
6606
  });
6526
6607
  }
6527
6608
  });
@@ -6533,16 +6614,16 @@ var lazyCompilation_exports = {};
6533
6614
  __export(lazyCompilation_exports, {
6534
6615
  pluginLazyCompilation: () => pluginLazyCompilation
6535
6616
  });
6536
- var import_shared56, pluginLazyCompilation;
6617
+ var import_shared55, pluginLazyCompilation;
6537
6618
  var init_lazyCompilation = __esm({
6538
6619
  "src/plugins/lazyCompilation.ts"() {
6539
6620
  "use strict";
6540
- import_shared56 = require("@rsbuild/shared");
6621
+ import_shared55 = require("@rsbuild/shared");
6541
6622
  pluginLazyCompilation = () => ({
6542
6623
  name: "rsbuild:lazy-compilation",
6543
6624
  setup(api) {
6544
- api.modifyBundlerChain((chain, { isProd: isProd4, target }) => {
6545
- if (isProd4 || target !== "web") {
6625
+ api.modifyBundlerChain((chain, { isProd: isProd5, target }) => {
6626
+ if (isProd5 || target !== "web") {
6546
6627
  return;
6547
6628
  }
6548
6629
  const config = api.getNormalizedConfig();
@@ -6550,12 +6631,10 @@ var init_lazyCompilation = __esm({
6550
6631
  if (!options) {
6551
6632
  return;
6552
6633
  }
6553
- const clientRegExp = /[\\/]core[\\/]dist[\\/]client[\\/]/;
6554
6634
  const cssRegExp = /\.(?:css|less|sass|scss|styl|stylus)$/;
6555
6635
  const isExcludedModule = (name) => {
6556
6636
  return (
6557
- // alway include Rsbuild client code, such as HMR
6558
- clientRegExp.test(name) || // exclude CSS files because Rspack does not support it yet
6637
+ // exclude CSS files because Rspack does not support it yet
6559
6638
  // TODO: remove this after Rspack supporting it
6560
6639
  cssRegExp.test(name)
6561
6640
  );
@@ -6585,7 +6664,7 @@ var init_lazyCompilation = __esm({
6585
6664
  if (!name || isExcludedModule(name)) {
6586
6665
  return false;
6587
6666
  }
6588
- if ((0, import_shared56.isRegExp)(test)) {
6667
+ if ((0, import_shared55.isRegExp)(test)) {
6589
6668
  return name ? test.test(name) : false;
6590
6669
  }
6591
6670
  return test(module2);
@@ -6602,6 +6681,222 @@ var init_lazyCompilation = __esm({
6602
6681
  }
6603
6682
  });
6604
6683
 
6684
+ // src/plugins/sri.ts
6685
+ var sri_exports = {};
6686
+ __export(sri_exports, {
6687
+ pluginSri: () => pluginSri
6688
+ });
6689
+ var import_node_crypto2, import_shared56, getAssetName, pluginSri;
6690
+ var init_sri = __esm({
6691
+ "src/plugins/sri.ts"() {
6692
+ "use strict";
6693
+ import_node_crypto2 = __toESM(require("crypto"));
6694
+ import_shared56 = require("@rsbuild/shared");
6695
+ init_constants();
6696
+ getAssetName = (url2, assetPrefix) => {
6697
+ if (url2.startsWith(assetPrefix)) {
6698
+ return (0, import_shared56.removeLeadingSlash)(url2.replace(assetPrefix, ""));
6699
+ }
6700
+ return (0, import_shared56.removeLeadingSlash)(url2);
6701
+ };
6702
+ pluginSri = () => ({
6703
+ name: "rsbuild:sri",
6704
+ setup(api) {
6705
+ const placeholder = "RSBUILD_INTEGRITY_PLACEHOLDER:";
6706
+ const getAlgorithm = () => {
6707
+ const config = api.getNormalizedConfig();
6708
+ const { sri } = config.security;
6709
+ const enable = sri.enable === "auto" ? (0, import_shared56.isProd)() : sri.enable;
6710
+ if (!enable) {
6711
+ return null;
6712
+ }
6713
+ const { algorithm = "sha384" } = sri;
6714
+ return algorithm;
6715
+ };
6716
+ api.modifyHTMLTags({
6717
+ // ensure `sri` can be applied to all tags
6718
+ order: "post",
6719
+ handler(tags, { assetPrefix }) {
6720
+ const algorithm = getAlgorithm();
6721
+ if (!algorithm) {
6722
+ return tags;
6723
+ }
6724
+ const allTags = [...tags.headTags, ...tags.bodyTags];
6725
+ for (const tag of allTags) {
6726
+ let url2 = "";
6727
+ if (!tag.attrs) {
6728
+ continue;
6729
+ }
6730
+ if (tag.tag === "script" && typeof tag.attrs.src === "string") {
6731
+ url2 = tag.attrs.src;
6732
+ } else if (tag.tag === "link" && tag.attrs.rel === "stylesheet" && typeof tag.attrs.href === "string") {
6733
+ url2 = tag.attrs.href;
6734
+ }
6735
+ if (!url2) {
6736
+ continue;
6737
+ }
6738
+ const assetName = getAssetName(url2, assetPrefix);
6739
+ if (!assetName) {
6740
+ continue;
6741
+ }
6742
+ tag.attrs.integrity ??= `${placeholder}${assetName}`;
6743
+ }
6744
+ return tags;
6745
+ }
6746
+ });
6747
+ const replaceIntegrity = (htmlContent, assets, algorithm, integrityCache) => {
6748
+ const regex = /integrity="RSBUILD_INTEGRITY_PLACEHOLDER:([^"]+)"/g;
6749
+ const matches = htmlContent.matchAll(regex);
6750
+ let replacedHtml = htmlContent;
6751
+ const calcIntegrity = (algorithm2, assetName, data) => {
6752
+ if (integrityCache.has(assetName)) {
6753
+ return integrityCache.get(assetName);
6754
+ }
6755
+ const hash = import_node_crypto2.default.createHash(algorithm2).update(data).digest().toString("base64");
6756
+ const integrity = `${algorithm2}-${hash}`;
6757
+ integrityCache.set(assetName, integrity);
6758
+ return integrity;
6759
+ };
6760
+ for (const match of matches) {
6761
+ const assetName = match[1];
6762
+ if (!assetName) {
6763
+ continue;
6764
+ }
6765
+ if (assets[assetName]) {
6766
+ const integrity = calcIntegrity(
6767
+ algorithm,
6768
+ assetName,
6769
+ assets[assetName].buffer()
6770
+ );
6771
+ replacedHtml = replacedHtml.replaceAll(
6772
+ `integrity="${placeholder}${assetName}"`,
6773
+ `integrity="${integrity}"`
6774
+ );
6775
+ } else {
6776
+ import_shared56.logger.debug(
6777
+ `[rsbuild:sri] failed to generate integrity for ${assetName}.`
6778
+ );
6779
+ replacedHtml = replacedHtml.replace(
6780
+ `integrity="${placeholder}${assetName}"`,
6781
+ ""
6782
+ );
6783
+ }
6784
+ }
6785
+ return replacedHtml;
6786
+ };
6787
+ class SriReplaceIntegrityPlugin {
6788
+ constructor(algorithm) {
6789
+ __publicField(this, "algorithm");
6790
+ this.algorithm = algorithm;
6791
+ }
6792
+ apply(compiler) {
6793
+ compiler.hooks.compilation.tap(
6794
+ "SriReplaceIntegrityPlugin",
6795
+ (compilation) => {
6796
+ compilation.hooks.processAssets.tapPromise(
6797
+ {
6798
+ name: "SriReplaceIntegrityPlugin",
6799
+ // use to final stage to get the final asset content
6800
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
6801
+ },
6802
+ async (assets) => {
6803
+ const integrityCache = /* @__PURE__ */ new Map();
6804
+ for (const asset of Object.keys(assets)) {
6805
+ if (!HTML_REGEX.test(asset)) {
6806
+ continue;
6807
+ }
6808
+ const htmlContent = assets[asset].source();
6809
+ if (!htmlContent.includes(placeholder)) {
6810
+ continue;
6811
+ }
6812
+ assets[asset] = new compiler.webpack.sources.RawSource(
6813
+ replaceIntegrity(
6814
+ htmlContent,
6815
+ assets,
6816
+ this.algorithm,
6817
+ integrityCache
6818
+ )
6819
+ );
6820
+ }
6821
+ }
6822
+ );
6823
+ }
6824
+ );
6825
+ }
6826
+ }
6827
+ api.modifyBundlerChain((chain, { target }) => {
6828
+ const config = api.getNormalizedConfig();
6829
+ if ((0, import_shared56.isHtmlDisabled)(config, target)) {
6830
+ return;
6831
+ }
6832
+ const algorithm = getAlgorithm();
6833
+ if (!algorithm) {
6834
+ return;
6835
+ }
6836
+ chain.plugin("rsbuild-sri-replace").use(SriReplaceIntegrityPlugin, [algorithm]);
6837
+ });
6838
+ }
6839
+ });
6840
+ }
6841
+ });
6842
+
6843
+ // src/plugins/nonce.ts
6844
+ var nonce_exports = {};
6845
+ __export(nonce_exports, {
6846
+ pluginNonce: () => pluginNonce
6847
+ });
6848
+ var import_shared57, pluginNonce;
6849
+ var init_nonce = __esm({
6850
+ "src/plugins/nonce.ts"() {
6851
+ "use strict";
6852
+ import_shared57 = require("@rsbuild/shared");
6853
+ pluginNonce = () => ({
6854
+ name: "rsbuild:nonce",
6855
+ setup(api) {
6856
+ api.onAfterCreateCompiler(({ compiler }) => {
6857
+ const { nonce } = api.getNormalizedConfig().security;
6858
+ if (!nonce) {
6859
+ return;
6860
+ }
6861
+ (0, import_shared57.applyToCompiler)(compiler, (compiler2) => {
6862
+ const { plugins } = compiler2.options;
6863
+ const hasHTML = plugins.some(
6864
+ (plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
6865
+ );
6866
+ if (!hasHTML) {
6867
+ return;
6868
+ }
6869
+ const injectCode = (0, import_shared57.createVirtualModule)(
6870
+ `__webpack_nonce__ = "${nonce}";`
6871
+ );
6872
+ new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
6873
+ name: void 0
6874
+ }).apply(compiler2);
6875
+ });
6876
+ });
6877
+ api.modifyHTMLTags({
6878
+ // ensure `nonce` can be applied to all tags
6879
+ order: "post",
6880
+ handler: ({ headTags, bodyTags }) => {
6881
+ const config = api.getNormalizedConfig();
6882
+ const { nonce } = config.security;
6883
+ const allTags = [...headTags, ...bodyTags];
6884
+ if (nonce) {
6885
+ for (const tag of allTags) {
6886
+ if (tag.tag === "script" || tag.tag === "style") {
6887
+ tag.attrs ??= {};
6888
+ tag.attrs.nonce = nonce;
6889
+ }
6890
+ }
6891
+ }
6892
+ return { headTags, bodyTags };
6893
+ }
6894
+ });
6895
+ }
6896
+ });
6897
+ }
6898
+ });
6899
+
6605
6900
  // src/createRsbuild.ts
6606
6901
  var createRsbuild_exports = {};
6607
6902
  __export(createRsbuild_exports, {
@@ -6629,7 +6924,7 @@ async function applyDefaultPlugins(pluginManager, context) {
6629
6924
  const { pluginSwc: pluginSwc2 } = await Promise.resolve().then(() => (init_swc(), swc_exports));
6630
6925
  const { pluginExternals: pluginExternals2 } = await Promise.resolve().then(() => (init_externals(), externals_exports));
6631
6926
  const { pluginSplitChunks: pluginSplitChunks2 } = await Promise.resolve().then(() => (init_splitChunks(), splitChunks_exports));
6632
- const { pluginStartUrl: pluginStartUrl2 } = await Promise.resolve().then(() => (init_startUrl(), startUrl_exports));
6927
+ const { pluginOpen: pluginOpen2 } = await Promise.resolve().then(() => (init_open(), open_exports));
6633
6928
  const { pluginInlineChunk: pluginInlineChunk2 } = await Promise.resolve().then(() => (init_inlineChunk(), inlineChunk_exports));
6634
6929
  const { pluginBundleAnalyzer: pluginBundleAnalyzer2 } = await Promise.resolve().then(() => (init_bundleAnalyzer(), bundleAnalyzer_exports));
6635
6930
  const { pluginRsdoctor: pluginRsdoctor2 } = await Promise.resolve().then(() => (init_rsdoctor(), rsdoctor_exports));
@@ -6640,6 +6935,8 @@ async function applyDefaultPlugins(pluginManager, context) {
6640
6935
  const { pluginModuleFederation: pluginModuleFederation2 } = await Promise.resolve().then(() => (init_moduleFederation(), moduleFederation_exports));
6641
6936
  const { pluginRspackProfile: pluginRspackProfile2 } = await Promise.resolve().then(() => (init_rspackProfile(), rspackProfile_exports));
6642
6937
  const { pluginLazyCompilation: pluginLazyCompilation2 } = await Promise.resolve().then(() => (init_lazyCompilation(), lazyCompilation_exports));
6938
+ const { pluginSri: pluginSri2 } = await Promise.resolve().then(() => (init_sri(), sri_exports));
6939
+ const { pluginNonce: pluginNonce2 } = await Promise.resolve().then(() => (init_nonce(), nonce_exports));
6643
6940
  pluginManager.addPlugins([
6644
6941
  pluginBasic2(),
6645
6942
  pluginEntry2(),
@@ -6651,8 +6948,8 @@ async function applyDefaultPlugins(pluginManager, context) {
6651
6948
  // cleanOutput plugin should before the html plugin
6652
6949
  pluginCleanOutput2(),
6653
6950
  pluginAsset2(),
6654
- pluginHtml2(async (tags) => {
6655
- const result = await context.hooks.modifyHTMLTags.call(tags);
6951
+ pluginHtml2(async (...args) => {
6952
+ const result = await context.hooks.modifyHTMLTags.call(...args);
6656
6953
  return result[0];
6657
6954
  }),
6658
6955
  pluginWasm2(),
@@ -6665,7 +6962,7 @@ async function applyDefaultPlugins(pluginManager, context) {
6665
6962
  pluginSwc2(),
6666
6963
  pluginExternals2(),
6667
6964
  pluginSplitChunks2(),
6668
- pluginStartUrl2(),
6965
+ pluginOpen2(),
6669
6966
  pluginInlineChunk2(),
6670
6967
  pluginBundleAnalyzer2(),
6671
6968
  pluginRsdoctor2(),
@@ -6675,7 +6972,9 @@ async function applyDefaultPlugins(pluginManager, context) {
6675
6972
  pluginManifest2(),
6676
6973
  pluginModuleFederation2(),
6677
6974
  pluginRspackProfile2(),
6678
- pluginLazyCompilation2()
6975
+ pluginLazyCompilation2(),
6976
+ pluginSri2(),
6977
+ pluginNonce2()
6679
6978
  ]);
6680
6979
  }
6681
6980
  async function createRsbuild(options = {}) {
@@ -6693,9 +6992,9 @@ async function createRsbuild(options = {}) {
6693
6992
  );
6694
6993
  const pluginAPI = getPluginAPI({ context, pluginManager });
6695
6994
  context.pluginAPI = pluginAPI;
6696
- (0, import_shared57.debug)("add default plugins");
6995
+ (0, import_shared58.debug)("add default plugins");
6697
6996
  await applyDefaultPlugins(pluginManager, context);
6698
- (0, import_shared57.debug)("add default plugins done");
6997
+ (0, import_shared58.debug)("add default plugins done");
6699
6998
  const provider = rsbuildConfig.provider || await getRspackProvider();
6700
6999
  const providerInstance = await provider({
6701
7000
  context,
@@ -6704,13 +7003,13 @@ async function createRsbuild(options = {}) {
6704
7003
  setCssExtractPlugin
6705
7004
  });
6706
7005
  const rsbuild = {
6707
- ...(0, import_shared57.pick)(pluginManager, [
7006
+ ...(0, import_shared58.pick)(pluginManager, [
6708
7007
  "addPlugins",
6709
7008
  "getPlugins",
6710
7009
  "removePlugins",
6711
7010
  "isPluginExists"
6712
7011
  ]),
6713
- ...(0, import_shared57.pick)(pluginAPI, [
7012
+ ...(0, import_shared58.pick)(pluginAPI, [
6714
7013
  "onBeforeBuild",
6715
7014
  "onBeforeCreateCompiler",
6716
7015
  "onBeforeStartDevServer",
@@ -6726,7 +7025,7 @@ async function createRsbuild(options = {}) {
6726
7025
  "getRsbuildConfig",
6727
7026
  "getNormalizedConfig"
6728
7027
  ]),
6729
- ...(0, import_shared57.pick)(providerInstance, [
7028
+ ...(0, import_shared58.pick)(providerInstance, [
6730
7029
  "build",
6731
7030
  "preview",
6732
7031
  "initConfigs",
@@ -6743,11 +7042,11 @@ async function createRsbuild(options = {}) {
6743
7042
  }
6744
7043
  return rsbuild;
6745
7044
  }
6746
- var import_shared57, getRspackProvider, pickRsbuildConfig;
7045
+ var import_shared58, getRspackProvider, pickRsbuildConfig;
6747
7046
  var init_createRsbuild = __esm({
6748
7047
  "src/createRsbuild.ts"() {
6749
7048
  "use strict";
6750
- import_shared57 = require("@rsbuild/shared");
7049
+ import_shared58 = require("@rsbuild/shared");
6751
7050
  init_createContext();
6752
7051
  init_initPlugins();
6753
7052
  init_pluginHelper();
@@ -6769,7 +7068,7 @@ var init_createRsbuild = __esm({
6769
7068
  "moduleFederation",
6770
7069
  "_privateMeta"
6771
7070
  ];
6772
- return (0, import_shared57.pick)(rsbuildConfig, keys);
7071
+ return (0, import_shared58.pick)(rsbuildConfig, keys);
6773
7072
  };
6774
7073
  }
6775
7074
  });
@@ -6788,7 +7087,7 @@ async function init({
6788
7087
  cwd: root,
6789
7088
  mode: cliOptions?.envMode
6790
7089
  });
6791
- if ((0, import_shared58.isDev)()) {
7090
+ if ((0, import_shared59.isDev)()) {
6792
7091
  onBeforeRestartServer(envs.cleanup);
6793
7092
  }
6794
7093
  const { content: config, filePath: configFilePath } = await loadConfig({
@@ -6810,9 +7109,9 @@ async function init({
6810
7109
  ...envs.publicVars,
6811
7110
  ...config.source.define
6812
7111
  };
6813
- if (commonOpts.open && !config.dev?.startUrl) {
6814
- config.dev ||= {};
6815
- config.dev.startUrl = commonOpts.open;
7112
+ if (commonOpts.open && !config.server?.open) {
7113
+ config.server ||= {};
7114
+ config.server.open = commonOpts.open;
6816
7115
  }
6817
7116
  if (commonOpts.host) {
6818
7117
  config.server ||= {};
@@ -6828,17 +7127,17 @@ async function init({
6828
7127
  });
6829
7128
  } catch (err) {
6830
7129
  if (isRestart) {
6831
- import_shared58.logger.error(err);
7130
+ import_shared59.logger.error(err);
6832
7131
  } else {
6833
7132
  throw err;
6834
7133
  }
6835
7134
  }
6836
7135
  }
6837
- var import_shared58, commonOpts;
7136
+ var import_shared59, commonOpts;
6838
7137
  var init_init = __esm({
6839
7138
  "src/cli/init.ts"() {
6840
7139
  "use strict";
6841
- import_shared58 = require("@rsbuild/shared");
7140
+ import_shared59 = require("@rsbuild/shared");
6842
7141
  init_config();
6843
7142
  init_loadEnv();
6844
7143
  init_restart();
@@ -6856,7 +7155,7 @@ __export(src_exports, {
6856
7155
  defineConfig: () => defineConfig,
6857
7156
  loadConfig: () => loadConfig,
6858
7157
  loadEnv: () => loadEnv,
6859
- logger: () => import_shared61.logger,
7158
+ logger: () => import_shared62.logger,
6860
7159
  mergeRsbuildConfig: () => mergeRsbuildConfig,
6861
7160
  rspack: () => import_core10.rspack,
6862
7161
  version: () => version
@@ -6879,16 +7178,18 @@ __export(internal_exports, {
6879
7178
  initHooks: () => initHooks,
6880
7179
  initPlugins: () => initPlugins,
6881
7180
  initRsbuildConfig: () => initRsbuildConfig,
7181
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
6882
7182
  prepareCli: () => prepareCli,
6883
7183
  runCli: () => runCli,
6884
7184
  setHTMLPlugin: () => setHTMLPlugin,
6885
- startProdServer: () => startProdServer
7185
+ startProdServer: () => startProdServer,
7186
+ stringifyConfig: () => stringifyConfig
6886
7187
  });
6887
7188
 
6888
7189
  // src/cli/commands.ts
6889
7190
  var import_node_fs5 = require("fs");
6890
7191
  var import_node_path28 = require("path");
6891
- var import_shared59 = require("@rsbuild/shared");
7192
+ var import_shared60 = require("@rsbuild/shared");
6892
7193
  var import_commander = require("../compiled/commander/index.js");
6893
7194
  init_helpers();
6894
7195
  init_init();
@@ -6905,7 +7206,7 @@ var applyServerOptions = (command) => {
6905
7206
  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");
6906
7207
  };
6907
7208
  function runCli() {
6908
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.2");
7209
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.4");
6909
7210
  const devCommand = import_commander.program.command("dev");
6910
7211
  const buildCommand = import_commander.program.command("build");
6911
7212
  const previewCommand = import_commander.program.command("preview");
@@ -6919,8 +7220,8 @@ function runCli() {
6919
7220
  const rsbuild = await init({ cliOptions: options });
6920
7221
  await rsbuild?.startDevServer();
6921
7222
  } catch (err) {
6922
- import_shared59.logger.error("Failed to start dev server.");
6923
- import_shared59.logger.error(err);
7223
+ import_shared60.logger.error("Failed to start dev server.");
7224
+ import_shared60.logger.error(err);
6924
7225
  process.exit(1);
6925
7226
  }
6926
7227
  });
@@ -6931,8 +7232,8 @@ function runCli() {
6931
7232
  watch: options.watch
6932
7233
  });
6933
7234
  } catch (err) {
6934
- import_shared59.logger.error("Failed to build.");
6935
- import_shared59.logger.error(err);
7235
+ import_shared60.logger.error("Failed to build.");
7236
+ import_shared60.logger.error(err);
6936
7237
  process.exit(1);
6937
7238
  }
6938
7239
  });
@@ -6943,14 +7244,14 @@ function runCli() {
6943
7244
  const { distPath } = rsbuild.context;
6944
7245
  if (!(0, import_node_fs5.existsSync)(distPath)) {
6945
7246
  throw new Error(
6946
- `The output directory ${import_shared59.color.yellow(
7247
+ `The output directory ${import_shared60.color.yellow(
6947
7248
  distPath
6948
7249
  )} does not exist, please build the project before previewing.`
6949
7250
  );
6950
7251
  }
6951
7252
  if (isEmptyDir(distPath)) {
6952
7253
  throw new Error(
6953
- `The output directory ${import_shared59.color.yellow(
7254
+ `The output directory ${import_shared60.color.yellow(
6954
7255
  distPath
6955
7256
  )} is empty, please build the project before previewing.`
6956
7257
  );
@@ -6958,8 +7259,8 @@ function runCli() {
6958
7259
  }
6959
7260
  await rsbuild?.preview();
6960
7261
  } catch (err) {
6961
- import_shared59.logger.error("Failed to start preview server.");
6962
- import_shared59.logger.error(err);
7262
+ import_shared60.logger.error("Failed to start preview server.");
7263
+ import_shared60.logger.error(err);
6963
7264
  process.exit(1);
6964
7265
  }
6965
7266
  });
@@ -6973,8 +7274,8 @@ function runCli() {
6973
7274
  writeToDisk: true
6974
7275
  });
6975
7276
  } catch (err) {
6976
- import_shared59.logger.error("Failed to inspect config.");
6977
- import_shared59.logger.error(err);
7277
+ import_shared60.logger.error("Failed to inspect config.");
7278
+ import_shared60.logger.error(err);
6978
7279
  process.exit(1);
6979
7280
  }
6980
7281
  });
@@ -6982,7 +7283,7 @@ function runCli() {
6982
7283
  }
6983
7284
 
6984
7285
  // src/cli/prepare.ts
6985
- var import_shared60 = require("@rsbuild/shared");
7286
+ var import_shared61 = require("@rsbuild/shared");
6986
7287
  function initNodeEnv() {
6987
7288
  if (!process.env.NODE_ENV) {
6988
7289
  const command = process.argv[2];
@@ -6995,7 +7296,7 @@ function prepareCli() {
6995
7296
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
6996
7297
  console.log();
6997
7298
  }
6998
- import_shared60.logger.greet(` ${`Rsbuild v${"0.7.2"}`}
7299
+ import_shared61.logger.greet(` ${`Rsbuild v${"0.7.4"}`}
6999
7300
  `);
7000
7301
  }
7001
7302
 
@@ -7003,6 +7304,7 @@ function prepareCli() {
7003
7304
  init_pluginManager();
7004
7305
  init_initHooks();
7005
7306
  init_initConfigs();
7307
+ init_config();
7006
7308
  init_pluginHelper();
7007
7309
  init_helpers();
7008
7310
  init_rspackConfig();
@@ -7018,10 +7320,10 @@ init_prodServer();
7018
7320
  init_loadEnv();
7019
7321
  init_createRsbuild();
7020
7322
  init_config();
7021
- var import_shared61 = require("@rsbuild/shared");
7323
+ var import_shared62 = require("@rsbuild/shared");
7022
7324
  init_mergeConfig();
7023
7325
  init_constants();
7024
- var version = "0.7.2";
7326
+ var version = "0.7.4";
7025
7327
  // Annotate the CommonJS export names for ESM import in node:
7026
7328
  0 && (module.exports = {
7027
7329
  PLUGIN_CSS_NAME,