@rsbuild/core 0.7.0-beta.6 → 0.7.0-beta.7

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
@@ -333,8 +333,8 @@ var init_mergeConfig = __esm({
333
333
  "provider"
334
334
  ];
335
335
  isOverridePath = (key) => OVERRIDE_PATH.includes(key);
336
- merge = (x, y, path15 = "") => {
337
- if (isOverridePath(path15)) {
336
+ merge = (x, y, path13 = "") => {
337
+ if (isOverridePath(path13)) {
338
338
  return y ?? x;
339
339
  }
340
340
  if (x === void 0) {
@@ -356,7 +356,7 @@ var init_mergeConfig = __esm({
356
356
  const merged = {};
357
357
  const keys = /* @__PURE__ */ new Set([...Object.keys(x), ...Object.keys(y)]);
358
358
  for (const key of keys) {
359
- const childPath = path15 ? `${path15}.${key}` : key;
359
+ const childPath = path13 ? `${path13}.${key}` : key;
360
360
  merged[key] = merge(x[key], y[key], childPath);
361
361
  }
362
362
  return merged;
@@ -459,10 +459,10 @@ async function watchFiles(files) {
459
459
  }
460
460
  async function loadConfig({
461
461
  cwd = process.cwd(),
462
- path: path15,
462
+ path: path13,
463
463
  envMode
464
464
  } = {}) {
465
- const configFilePath = resolveConfigPath(cwd, path15);
465
+ const configFilePath = resolveConfigPath(cwd, path13);
466
466
  if (!configFilePath) {
467
467
  return {
468
468
  content: {},
@@ -1043,7 +1043,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
1043
1043
  const context = {
1044
1044
  entry: getEntryObject(config, "web"),
1045
1045
  targets: config.output?.targets || [],
1046
- version: "0.7.0-beta.6",
1046
+ version: "0.7.0-beta.7",
1047
1047
  rootPath,
1048
1048
  distPath,
1049
1049
  cachePath,
@@ -3434,10 +3434,10 @@ var init_rsdoctor = __esm({
3434
3434
  const packageName = isRspack ? "@rsdoctor/rspack-plugin" : "@rsdoctor/webpack-plugin";
3435
3435
  let module2;
3436
3436
  try {
3437
- const path15 = require.resolve(packageName, {
3437
+ const path13 = require.resolve(packageName, {
3438
3438
  paths: [api.context.rootPath]
3439
3439
  });
3440
- module2 = await import(path15);
3440
+ module2 = await import(path13);
3441
3441
  } catch (err) {
3442
3442
  import_shared30.logger.warn(
3443
3443
  `\`process.env.RSDOCTOR\` enabled, please install ${import_shared30.color.bold(import_shared30.color.yellow(packageName))} package.`
@@ -4100,227 +4100,17 @@ var init_define = __esm({
4100
4100
  }
4101
4101
  });
4102
4102
 
4103
- // src/plugins/less.ts
4104
- var less_exports = {};
4105
- __export(less_exports, {
4106
- pluginLess: () => pluginLess
4107
- });
4108
- function pluginLess() {
4109
- return {
4110
- name: "rsbuild:less",
4111
- setup(api) {
4112
- api.modifyBundlerChain(async (chain, utils) => {
4113
- const config = api.getNormalizedConfig();
4114
- const { applyCSSRule: applyCSSRule2 } = await Promise.resolve().then(() => (init_css(), css_exports));
4115
- const rule = chain.module.rule(utils.CHAIN_ID.RULE.LESS).test(/\.less$/);
4116
- const { excludes, options } = getLessLoaderOptions(
4117
- config.tools.less,
4118
- config.output.sourceMap.css,
4119
- api.context.rootPath
4120
- );
4121
- for (const item of excludes) {
4122
- rule.exclude.add(item);
4123
- }
4124
- await applyCSSRule2({
4125
- rule,
4126
- utils,
4127
- config,
4128
- context: api.context,
4129
- importLoaders: 2
4130
- });
4131
- rule.use(utils.CHAIN_ID.USE.LESS).loader(getCompiledPath("less-loader")).options(options);
4132
- });
4133
- }
4134
- };
4135
- }
4136
- var import_node_path21, import_shared37, getLessLoaderOptions;
4137
- var init_less = __esm({
4138
- "src/plugins/less.ts"() {
4139
- "use strict";
4140
- import_node_path21 = __toESM(require("path"));
4141
- import_shared37 = require("@rsbuild/shared");
4142
- init_helpers();
4143
- getLessLoaderOptions = (rsbuildLessConfig, isUseCssSourceMap, rootPath) => {
4144
- const excludes = [];
4145
- const addExcludes = (items) => {
4146
- excludes.push(...(0, import_shared37.castArray)(items));
4147
- };
4148
- const defaultLessLoaderOptions = {
4149
- lessOptions: {
4150
- javascriptEnabled: true,
4151
- // let less resolve from node_modules in the current root directory,
4152
- // Avoid resolving from wrong node_modules.
4153
- paths: [import_node_path21.default.join(rootPath, "node_modules")]
4154
- },
4155
- sourceMap: isUseCssSourceMap,
4156
- implementation: (0, import_shared37.getSharedPkgCompiledPath)("less")
4157
- };
4158
- const mergeFn = (defaults, userOptions) => {
4159
- const getLessOptions = () => {
4160
- if (defaults.lessOptions && userOptions.lessOptions) {
4161
- return (0, import_shared37.deepmerge)(defaults.lessOptions, userOptions.lessOptions);
4162
- }
4163
- return userOptions.lessOptions || defaults.lessOptions;
4164
- };
4165
- return {
4166
- ...defaults,
4167
- ...userOptions,
4168
- lessOptions: getLessOptions()
4169
- };
4170
- };
4171
- const mergedOptions = (0, import_shared37.mergeChainedOptions)({
4172
- defaults: defaultLessLoaderOptions,
4173
- options: rsbuildLessConfig,
4174
- utils: { addExcludes },
4175
- mergeFn
4176
- });
4177
- return {
4178
- options: mergedOptions,
4179
- excludes
4180
- };
4181
- };
4182
- }
4183
- });
4184
-
4185
- // src/plugins/sass.ts
4186
- var sass_exports = {};
4187
- __export(sass_exports, {
4188
- patchCompilerGlobalLocation: () => patchCompilerGlobalLocation,
4189
- pluginSass: () => pluginSass
4190
- });
4191
- function patchGlobalLocation() {
4192
- if (!global.location) {
4193
- const href = (0, import_node_url2.pathToFileURL)(process.cwd()).href + import_node_path22.default.sep;
4194
- const location = Object.freeze({ [GLOBAL_PATCHED_SYMBOL]: true, href });
4195
- global.location = location;
4196
- }
4197
- }
4198
- function unpatchGlobalLocation() {
4199
- if (global.location?.[GLOBAL_PATCHED_SYMBOL]) {
4200
- delete global.location;
4201
- }
4202
- }
4203
- function patchCompilerGlobalLocation(compiler) {
4204
- compiler.hooks.run.tap("PatchGlobalLocation", patchGlobalLocation);
4205
- compiler.hooks.watchRun.tap("PatchGlobalLocation", patchGlobalLocation);
4206
- compiler.hooks.watchClose.tap("PatchGlobalLocation", unpatchGlobalLocation);
4207
- compiler.hooks.done.tap("PatchGlobalLocation", unpatchGlobalLocation);
4208
- }
4209
- function pluginSass() {
4210
- return {
4211
- name: "rsbuild:sass",
4212
- setup(api) {
4213
- api.onAfterCreateCompiler(({ compiler }) => {
4214
- patchCompilerGlobalLocation(compiler);
4215
- });
4216
- api.modifyBundlerChain(async (chain, utils) => {
4217
- const config = api.getNormalizedConfig();
4218
- const { applyCSSRule: applyCSSRule2 } = await Promise.resolve().then(() => (init_css(), css_exports));
4219
- const { excludes, options } = getSassLoaderOptions(
4220
- config.tools.sass,
4221
- // source-maps required for loaders preceding resolve-url-loader
4222
- // otherwise the resolve-url-loader will throw an error
4223
- true
4224
- );
4225
- const rule = chain.module.rule(utils.CHAIN_ID.RULE.SASS).test(/\.s(?:a|c)ss$/);
4226
- for (const item of excludes) {
4227
- rule.exclude.add(item);
4228
- }
4229
- await applyCSSRule2({
4230
- rule,
4231
- utils,
4232
- config,
4233
- context: api.context,
4234
- // postcss-loader, resolve-url-loader, sass-loader
4235
- importLoaders: 3
4236
- });
4237
- rule.use(utils.CHAIN_ID.USE.RESOLVE_URL).loader(getCompiledPath("resolve-url-loader")).options({
4238
- join: await getResolveUrlJoinFn(),
4239
- // 'resolve-url-loader' relies on 'adjust-sourcemap-loader',
4240
- // it has performance regression issues in some scenarios,
4241
- // so we need to disable the sourceMap option.
4242
- sourceMap: false
4243
- }).end().use(utils.CHAIN_ID.USE.SASS).loader((0, import_shared38.getSharedPkgCompiledPath)("sass-loader")).options(options);
4244
- });
4245
- }
4246
- };
4247
- }
4248
- var import_node_path22, import_node_url2, import_shared38, GLOBAL_PATCHED_SYMBOL, getSassLoaderOptions, getResolveUrlJoinFn;
4249
- var init_sass = __esm({
4250
- "src/plugins/sass.ts"() {
4251
- "use strict";
4252
- import_node_path22 = __toESM(require("path"));
4253
- import_node_url2 = require("url");
4254
- import_shared38 = require("@rsbuild/shared");
4255
- init_helpers();
4256
- GLOBAL_PATCHED_SYMBOL = Symbol("GLOBAL_PATCHED_SYMBOL");
4257
- getSassLoaderOptions = (rsbuildSassConfig, isUseCssSourceMap) => {
4258
- const excludes = [];
4259
- const addExcludes = (items) => {
4260
- excludes.push(...(0, import_shared38.castArray)(items));
4261
- };
4262
- const mergeFn = (defaults, userOptions) => {
4263
- const getSassOptions = () => {
4264
- if (defaults.sassOptions && userOptions.sassOptions) {
4265
- return (0, import_shared38.deepmerge)(
4266
- defaults.sassOptions,
4267
- userOptions.sassOptions
4268
- );
4269
- }
4270
- return userOptions.sassOptions || defaults.sassOptions;
4271
- };
4272
- return {
4273
- ...defaults,
4274
- ...userOptions,
4275
- sassOptions: getSassOptions()
4276
- };
4277
- };
4278
- const mergedOptions = (0, import_shared38.mergeChainedOptions)({
4279
- defaults: {
4280
- sourceMap: isUseCssSourceMap,
4281
- implementation: (0, import_shared38.getSharedPkgCompiledPath)("sass")
4282
- },
4283
- options: rsbuildSassConfig,
4284
- utils: { addExcludes },
4285
- mergeFn
4286
- });
4287
- return {
4288
- options: mergedOptions,
4289
- excludes
4290
- };
4291
- };
4292
- getResolveUrlJoinFn = async () => {
4293
- const {
4294
- createJoinFunction,
4295
- asGenerator,
4296
- createJoinImplementation,
4297
- defaultJoinGenerator
4298
- } = await import("../compiled/resolve-url-loader/index.js");
4299
- const rsbuildGenerator = asGenerator((item, ...rest) => {
4300
- if (!item.uri.startsWith(".")) {
4301
- return [null];
4302
- }
4303
- return defaultJoinGenerator(item, ...rest);
4304
- });
4305
- return createJoinFunction(
4306
- "rsbuild-resolve-join-fn",
4307
- createJoinImplementation(rsbuildGenerator)
4308
- );
4309
- };
4310
- }
4311
- });
4312
-
4313
4103
  // src/plugins/server.ts
4314
4104
  var server_exports = {};
4315
4105
  __export(server_exports, {
4316
4106
  pluginServer: () => pluginServer
4317
4107
  });
4318
- var import_node_path23, import_shared39, pluginServer;
4108
+ var import_node_path21, import_shared37, pluginServer;
4319
4109
  var init_server = __esm({
4320
4110
  "src/plugins/server.ts"() {
4321
4111
  "use strict";
4322
- import_node_path23 = require("path");
4323
- import_shared39 = require("@rsbuild/shared");
4112
+ import_node_path21 = require("path");
4113
+ import_shared37 = require("@rsbuild/shared");
4324
4114
  pluginServer = () => ({
4325
4115
  name: "rsbuild:server",
4326
4116
  setup(api) {
@@ -4331,12 +4121,12 @@ var init_server = __esm({
4331
4121
  if (!copyOnBuild || !name) {
4332
4122
  return;
4333
4123
  }
4334
- const publicDir = (0, import_node_path23.isAbsolute)(name) ? name : (0, import_node_path23.join)(api.context.rootPath, name);
4335
- if (!import_shared39.fse.existsSync(publicDir)) {
4124
+ const publicDir = (0, import_node_path21.isAbsolute)(name) ? name : (0, import_node_path21.join)(api.context.rootPath, name);
4125
+ if (!import_shared37.fse.existsSync(publicDir)) {
4336
4126
  return;
4337
4127
  }
4338
4128
  try {
4339
- await import_shared39.fse.copy(publicDir, api.context.distPath, {
4129
+ await import_shared37.fse.copy(publicDir, api.context.distPath, {
4340
4130
  // dereference symlinks
4341
4131
  dereference: true
4342
4132
  });
@@ -4386,18 +4176,18 @@ function pluginModuleFederation() {
4386
4176
  chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
4387
4177
  }
4388
4178
  const publicPath = chain.output.get("publicPath");
4389
- if (publicPath === import_shared40.DEFAULT_ASSET_PREFIX) {
4179
+ if (publicPath === import_shared38.DEFAULT_ASSET_PREFIX) {
4390
4180
  chain.output.set("publicPath", "auto");
4391
4181
  }
4392
4182
  });
4393
4183
  }
4394
4184
  };
4395
4185
  }
4396
- var import_shared40, import_core4, PatchSplitChunksPlugin;
4186
+ var import_shared38, import_core4, PatchSplitChunksPlugin;
4397
4187
  var init_moduleFederation = __esm({
4398
4188
  "src/plugins/moduleFederation.ts"() {
4399
4189
  "use strict";
4400
- import_shared40 = require("@rsbuild/shared");
4190
+ import_shared38 = require("@rsbuild/shared");
4401
4191
  import_core4 = require("@rspack/core");
4402
4192
  PatchSplitChunksPlugin = class {
4403
4193
  constructor(name) {
@@ -4605,8 +4395,6 @@ var init_plugins = __esm({
4605
4395
  performance: () => Promise.resolve().then(() => (init_performance(), performance_exports)).then((m) => m.pluginPerformance()),
4606
4396
  define: () => Promise.resolve().then(() => (init_define(), define_exports)).then((m) => m.pluginDefine()),
4607
4397
  css: () => Promise.resolve().then(() => (init_css(), css_exports)).then((m) => m.pluginCss()),
4608
- less: () => Promise.resolve().then(() => (init_less(), less_exports)).then((m) => m.pluginLess()),
4609
- sass: () => Promise.resolve().then(() => (init_sass(), sass_exports)).then((m) => m.pluginSass()),
4610
4398
  server: () => Promise.resolve().then(() => (init_server(), server_exports)).then((m) => m.pluginServer()),
4611
4399
  moduleFederation: () => Promise.resolve().then(() => (init_moduleFederation(), moduleFederation_exports)).then((m) => m.pluginModuleFederation()),
4612
4400
  manifest: () => Promise.resolve().then(() => (init_manifest(), manifest_exports)).then((m) => m.pluginManifest())
@@ -4627,9 +4415,9 @@ async function inspectConfig({
4627
4415
  inspectOptions = {}
4628
4416
  }) {
4629
4417
  if (inspectOptions.env) {
4630
- (0, import_shared41.setNodeEnv)(inspectOptions.env);
4631
- } else if (!(0, import_shared41.getNodeEnv)()) {
4632
- (0, import_shared41.setNodeEnv)("development");
4418
+ (0, import_shared39.setNodeEnv)(inspectOptions.env);
4419
+ } else if (!(0, import_shared39.getNodeEnv)()) {
4420
+ (0, import_shared39.setNodeEnv)("development");
4633
4421
  }
4634
4422
  const rspackConfigs = bundlerConfigs || (await initConfigs({
4635
4423
  context,
@@ -4640,21 +4428,21 @@ async function inspectConfig({
4640
4428
  ...context.normalizedConfig,
4641
4429
  pluginNames: pluginManager.getPlugins().map((p) => p.name)
4642
4430
  };
4643
- const rawRsbuildConfig = await (0, import_shared41.stringifyConfig)(
4431
+ const rawRsbuildConfig = await (0, import_shared39.stringifyConfig)(
4644
4432
  rsbuildDebugConfig,
4645
4433
  inspectOptions.verbose
4646
4434
  );
4647
4435
  const rawBundlerConfigs = await Promise.all(
4648
4436
  rspackConfigs.map(
4649
- (config) => (0, import_shared41.stringifyConfig)(config, inspectOptions.verbose)
4437
+ (config) => (0, import_shared39.stringifyConfig)(config, inspectOptions.verbose)
4650
4438
  )
4651
4439
  );
4652
4440
  let outputPath = inspectOptions.outputPath || context.distPath;
4653
- if (!(0, import_node_path24.isAbsolute)(outputPath)) {
4654
- outputPath = (0, import_node_path24.join)(context.rootPath, outputPath);
4441
+ if (!(0, import_node_path22.isAbsolute)(outputPath)) {
4442
+ outputPath = (0, import_node_path22.join)(context.rootPath, outputPath);
4655
4443
  }
4656
4444
  if (inspectOptions.writeToDisk) {
4657
- await (0, import_shared41.outputInspectConfigFiles)({
4445
+ await (0, import_shared39.outputInspectConfigFiles)({
4658
4446
  rsbuildConfig: context.normalizedConfig,
4659
4447
  rawRsbuildConfig,
4660
4448
  bundlerConfigs: rawBundlerConfigs,
@@ -4674,32 +4462,32 @@ async function inspectConfig({
4674
4462
  }
4675
4463
  };
4676
4464
  }
4677
- var import_node_path24, import_shared41;
4465
+ var import_node_path22, import_shared39;
4678
4466
  var init_inspectConfig = __esm({
4679
4467
  "src/provider/inspectConfig.ts"() {
4680
4468
  "use strict";
4681
- import_node_path24 = require("path");
4682
- import_shared41 = require("@rsbuild/shared");
4469
+ import_node_path22 = require("path");
4470
+ import_shared39 = require("@rsbuild/shared");
4683
4471
  init_initConfigs();
4684
4472
  }
4685
4473
  });
4686
4474
 
4687
4475
  // src/provider/rspackConfig.ts
4688
4476
  async function modifyRspackConfig(context, rspackConfig, utils) {
4689
- (0, import_shared42.debug)("modify Rspack config");
4477
+ (0, import_shared40.debug)("modify Rspack config");
4690
4478
  let [modifiedConfig] = await context.hooks.modifyRspackConfig.call(
4691
4479
  rspackConfig,
4692
4480
  utils
4693
4481
  );
4694
4482
  if (context.config.tools?.rspack) {
4695
- modifiedConfig = (0, import_shared42.mergeChainedOptions)({
4483
+ modifiedConfig = (0, import_shared40.mergeChainedOptions)({
4696
4484
  defaults: modifiedConfig,
4697
4485
  options: context.config.tools.rspack,
4698
4486
  utils,
4699
4487
  mergeFn: utils.mergeConfig
4700
4488
  });
4701
4489
  }
4702
- (0, import_shared42.debug)("modify Rspack config done");
4490
+ (0, import_shared40.debug)("modify Rspack config done");
4703
4491
  return modifiedConfig;
4704
4492
  }
4705
4493
  async function getConfigUtils(config, chainUtils) {
@@ -4709,7 +4497,7 @@ async function getConfigUtils(config, chainUtils) {
4709
4497
  rspack: import_core5.rspack,
4710
4498
  mergeConfig: merge2,
4711
4499
  addRules(rules) {
4712
- const ruleArr = (0, import_shared42.castArray)(rules);
4500
+ const ruleArr = (0, import_shared40.castArray)(rules);
4713
4501
  if (!config.module) {
4714
4502
  config.module = {};
4715
4503
  }
@@ -4719,14 +4507,14 @@ async function getConfigUtils(config, chainUtils) {
4719
4507
  config.module.rules.unshift(...ruleArr);
4720
4508
  },
4721
4509
  prependPlugins(plugins2) {
4722
- const pluginArr = (0, import_shared42.castArray)(plugins2);
4510
+ const pluginArr = (0, import_shared40.castArray)(plugins2);
4723
4511
  if (!config.plugins) {
4724
4512
  config.plugins = [];
4725
4513
  }
4726
4514
  config.plugins.unshift(...pluginArr);
4727
4515
  },
4728
4516
  appendPlugins(plugins2) {
4729
- const pluginArr = (0, import_shared42.castArray)(plugins2);
4517
+ const pluginArr = (0, import_shared40.castArray)(plugins2);
4730
4518
  if (!config.plugins) {
4731
4519
  config.plugins = [];
4732
4520
  }
@@ -4742,7 +4530,7 @@ async function getConfigUtils(config, chainUtils) {
4742
4530
  };
4743
4531
  }
4744
4532
  function getChainUtils(target) {
4745
- const nodeEnv = (0, import_shared42.getNodeEnv)();
4533
+ const nodeEnv = (0, import_shared40.getNodeEnv)();
4746
4534
  return {
4747
4535
  env: nodeEnv,
4748
4536
  target,
@@ -4751,7 +4539,7 @@ function getChainUtils(target) {
4751
4539
  isServer: target === "node",
4752
4540
  isWebWorker: target === "web-worker",
4753
4541
  isServiceWorker: target === "service-worker",
4754
- CHAIN_ID: import_shared42.CHAIN_ID,
4542
+ CHAIN_ID: import_shared40.CHAIN_ID,
4755
4543
  HtmlPlugin: getHTMLPlugin()
4756
4544
  };
4757
4545
  }
@@ -4767,7 +4555,7 @@ async function generateRspackConfig({
4767
4555
  ProvidePlugin,
4768
4556
  HotModuleReplacementPlugin
4769
4557
  } = import_core5.rspack;
4770
- const chain = await (0, import_shared42.modifyBundlerChain)(context, {
4558
+ const chain = await (0, import_shared40.modifyBundlerChain)(context, {
4771
4559
  ...chainUtils,
4772
4560
  bundler: {
4773
4561
  BannerPlugin,
@@ -4777,7 +4565,7 @@ async function generateRspackConfig({
4777
4565
  HotModuleReplacementPlugin
4778
4566
  }
4779
4567
  });
4780
- let rspackConfig = (0, import_shared42.chainToConfig)(chain);
4568
+ let rspackConfig = (0, import_shared40.chainToConfig)(chain);
4781
4569
  rspackConfig = await modifyRspackConfig(
4782
4570
  context,
4783
4571
  rspackConfig,
@@ -4785,11 +4573,11 @@ async function generateRspackConfig({
4785
4573
  );
4786
4574
  return rspackConfig;
4787
4575
  }
4788
- var import_shared42, import_core5;
4576
+ var import_shared40, import_core5;
4789
4577
  var init_rspackConfig = __esm({
4790
4578
  "src/provider/rspackConfig.ts"() {
4791
4579
  "use strict";
4792
- import_shared42 = require("@rsbuild/shared");
4580
+ import_shared40 = require("@rsbuild/shared");
4793
4581
  import_core5 = require("@rspack/core");
4794
4582
  init_pluginHelper();
4795
4583
  }
@@ -4797,13 +4585,13 @@ var init_rspackConfig = __esm({
4797
4585
 
4798
4586
  // src/provider/initConfigs.ts
4799
4587
  async function modifyRsbuildConfig(context) {
4800
- (0, import_shared43.debug)("modify Rsbuild config");
4588
+ (0, import_shared41.debug)("modify Rsbuild config");
4801
4589
  const [modified] = await context.hooks.modifyRsbuildConfig.call(
4802
4590
  context.config,
4803
4591
  { mergeRsbuildConfig }
4804
4592
  );
4805
4593
  context.config = modified;
4806
- (0, import_shared43.debug)("modify Rsbuild config done");
4594
+ (0, import_shared41.debug)("modify Rsbuild config done");
4807
4595
  }
4808
4596
  async function initRsbuildConfig({
4809
4597
  context,
@@ -4831,7 +4619,7 @@ async function initConfigs({
4831
4619
  const rspackConfigs = await Promise.all(
4832
4620
  targets.map((target) => generateRspackConfig({ target, context }))
4833
4621
  );
4834
- if ((0, import_shared43.isDebug)()) {
4622
+ if ((0, import_shared41.isDebug)()) {
4835
4623
  const inspect = () => {
4836
4624
  const inspectOptions = {
4837
4625
  verbose: true,
@@ -4852,11 +4640,11 @@ async function initConfigs({
4852
4640
  rspackConfigs
4853
4641
  };
4854
4642
  }
4855
- var import_shared43;
4643
+ var import_shared41;
4856
4644
  var init_initConfigs = __esm({
4857
4645
  "src/provider/initConfigs.ts"() {
4858
4646
  "use strict";
4859
- import_shared43 = require("@rsbuild/shared");
4647
+ import_shared41 = require("@rsbuild/shared");
4860
4648
  init_config();
4861
4649
  init_createContext();
4862
4650
  init_mergeConfig();
@@ -4878,7 +4666,7 @@ function applyHMREntry({
4878
4666
  clientConfig = {},
4879
4667
  liveReload = true
4880
4668
  }) {
4881
- if (!(0, import_shared44.isClientCompiler)(compiler)) {
4669
+ if (!(0, import_shared42.isClientCompiler)(compiler)) {
4882
4670
  return;
4883
4671
  }
4884
4672
  new compiler.webpack.DefinePlugin({
@@ -4891,13 +4679,13 @@ function applyHMREntry({
4891
4679
  }).apply(compiler);
4892
4680
  }
4893
4681
  }
4894
- var import_shared44, setupServerHooks, getDevMiddleware;
4682
+ var import_shared42, setupServerHooks, getDevMiddleware;
4895
4683
  var init_devMiddleware = __esm({
4896
4684
  "src/server/devMiddleware.ts"() {
4897
4685
  "use strict";
4898
- import_shared44 = require("@rsbuild/shared");
4686
+ import_shared42 = require("@rsbuild/shared");
4899
4687
  setupServerHooks = (compiler, hookCallbacks) => {
4900
- if ((0, import_shared44.isNodeCompiler)(compiler)) {
4688
+ if ((0, import_shared42.isNodeCompiler)(compiler)) {
4901
4689
  return;
4902
4690
  }
4903
4691
  const { compile, invalid, done } = compiler.hooks;
@@ -4920,7 +4708,7 @@ var init_devMiddleware = __esm({
4920
4708
  }
4921
4709
  setupServerHooks(compiler, callbacks);
4922
4710
  };
4923
- (0, import_shared44.applyToCompiler)(multiCompiler, setupCompiler);
4711
+ (0, import_shared42.applyToCompiler)(multiCompiler, setupCompiler);
4924
4712
  return webpackDevMiddleware(multiCompiler, restOptions);
4925
4713
  };
4926
4714
  };
@@ -4937,13 +4725,13 @@ async function createCompiler({
4937
4725
  context,
4938
4726
  rspackConfigs
4939
4727
  }) {
4940
- (0, import_shared45.debug)("create compiler");
4728
+ (0, import_shared43.debug)("create compiler");
4941
4729
  await context.hooks.onBeforeCreateCompiler.call({
4942
4730
  bundlerConfigs: rspackConfigs
4943
4731
  });
4944
4732
  if (!await isSatisfyRspackVersion(import_core6.rspack.rspackVersion)) {
4945
4733
  throw new Error(
4946
- `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared45.color.green(
4734
+ `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared43.color.green(
4947
4735
  rspackMinVersion
4948
4736
  )}`
4949
4737
  );
@@ -4954,18 +4742,18 @@ async function createCompiler({
4954
4742
  let isCompiling = false;
4955
4743
  const logRspackVersion = () => {
4956
4744
  if (!isVersionLogged) {
4957
- (0, import_shared45.debug)(`Use Rspack v${import_core6.rspack.rspackVersion}`);
4745
+ (0, import_shared43.debug)(`Use Rspack v${import_core6.rspack.rspackVersion}`);
4958
4746
  isVersionLogged = true;
4959
4747
  }
4960
4748
  };
4961
4749
  compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
4962
4750
  logRspackVersion();
4963
4751
  if (!isCompiling) {
4964
- import_shared45.logger.start("Compiling...");
4752
+ import_shared43.logger.start("Compiling...");
4965
4753
  }
4966
4754
  isCompiling = true;
4967
4755
  });
4968
- if ((0, import_shared45.isProd)()) {
4756
+ if ((0, import_shared43.isProd)()) {
4969
4757
  compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
4970
4758
  }
4971
4759
  const done = async (stats) => {
@@ -4975,10 +4763,10 @@ async function createCompiler({
4975
4763
  });
4976
4764
  const printTime = (c, index) => {
4977
4765
  if (c.time) {
4978
- const time = (0, import_shared45.prettyTime)(c.time / 1e3);
4766
+ const time = (0, import_shared43.prettyTime)(c.time / 1e3);
4979
4767
  const target = context.targets[index];
4980
- const name = import_shared45.TARGET_ID_MAP[target || "web"];
4981
- import_shared45.logger.ready(`${name} compiled in ${time}`);
4768
+ const name = import_shared43.TARGET_ID_MAP[target || "web"];
4769
+ import_shared43.logger.ready(`${name} compiled in ${time}`);
4982
4770
  }
4983
4771
  };
4984
4772
  if (!stats.hasErrors()) {
@@ -4992,12 +4780,12 @@ async function createCompiler({
4992
4780
  }
4993
4781
  const { message, level } = formatStats(stats, getStatsOptions(compiler));
4994
4782
  if (level === "error") {
4995
- import_shared45.logger.error(message);
4783
+ import_shared43.logger.error(message);
4996
4784
  }
4997
4785
  if (level === "warning") {
4998
- import_shared45.logger.warn(message);
4786
+ import_shared43.logger.warn(message);
4999
4787
  }
5000
- if ((0, import_shared45.isDev)()) {
4788
+ if ((0, import_shared43.isDev)()) {
5001
4789
  await context.hooks.onDevCompileDone.call({
5002
4790
  isFirstCompile,
5003
4791
  stats
@@ -5006,14 +4794,14 @@ async function createCompiler({
5006
4794
  isCompiling = false;
5007
4795
  isFirstCompile = false;
5008
4796
  };
5009
- (0, import_shared45.onCompileDone)(
4797
+ (0, import_shared43.onCompileDone)(
5010
4798
  compiler,
5011
4799
  done,
5012
4800
  // @ts-expect-error type mismatch
5013
4801
  import_core6.rspack.MultiStats
5014
4802
  );
5015
4803
  await context.hooks.onAfterCreateCompiler.call({ compiler });
5016
- (0, import_shared45.debug)("create compiler done");
4804
+ (0, import_shared43.debug)("create compiler done");
5017
4805
  return compiler;
5018
4806
  }
5019
4807
  async function createDevMiddleware(options, customCompiler) {
@@ -5033,11 +4821,11 @@ async function createDevMiddleware(options, customCompiler) {
5033
4821
  compiler
5034
4822
  };
5035
4823
  }
5036
- var import_shared45, import_core6;
4824
+ var import_shared43, import_core6;
5037
4825
  var init_createCompiler = __esm({
5038
4826
  "src/provider/createCompiler.ts"() {
5039
4827
  "use strict";
5040
- import_shared45 = require("@rsbuild/shared");
4828
+ import_shared43 = require("@rsbuild/shared");
5041
4829
  import_core6 = require("@rspack/core");
5042
4830
  init_helpers();
5043
4831
  init_initConfigs();
@@ -5049,11 +4837,11 @@ var progress_exports = {};
5049
4837
  __export(progress_exports, {
5050
4838
  pluginProgress: () => pluginProgress
5051
4839
  });
5052
- var import_shared46, import_core7, pluginProgress;
4840
+ var import_shared44, import_core7, pluginProgress;
5053
4841
  var init_progress = __esm({
5054
4842
  "src/plugins/progress.ts"() {
5055
4843
  "use strict";
5056
- import_shared46 = require("@rsbuild/shared");
4844
+ import_shared44 = require("@rsbuild/shared");
5057
4845
  import_core7 = require("@rspack/core");
5058
4846
  pluginProgress = () => ({
5059
4847
  name: "rsbuild:progress",
@@ -5061,11 +4849,11 @@ var init_progress = __esm({
5061
4849
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3 }) => {
5062
4850
  const config = api.getNormalizedConfig();
5063
4851
  const options = config.dev.progressBar ?? // enable progress bar in production by default
5064
- (0, import_shared46.isProd)();
4852
+ (0, import_shared44.isProd)();
5065
4853
  if (!options) {
5066
4854
  return;
5067
4855
  }
5068
- const prefix = options !== true && options.id !== void 0 ? options.id : import_shared46.TARGET_ID_MAP[target];
4856
+ const prefix = options !== true && options.id !== void 0 ? options.id : import_shared44.TARGET_ID_MAP[target];
5069
4857
  chain.plugin(CHAIN_ID3.PLUGIN.PROGRESS).use(import_core7.rspack.ProgressPlugin, [
5070
4858
  {
5071
4859
  prefix,
@@ -5099,14 +4887,14 @@ async function getDefaultSwcConfig(config, rootPath, target) {
5099
4887
  },
5100
4888
  isModule: "unknown",
5101
4889
  env: {
5102
- targets: await (0, import_shared47.getBrowserslistWithDefault)(rootPath, config, target)
4890
+ targets: await (0, import_shared45.getBrowserslistWithDefault)(rootPath, config, target)
5103
4891
  }
5104
4892
  };
5105
4893
  }
5106
4894
  async function applyCoreJs(swcConfig, chain, polyfillMode) {
5107
4895
  const coreJsPath = require.resolve("core-js/package.json");
5108
- const version2 = (0, import_shared47.getCoreJsVersion)(coreJsPath);
5109
- const coreJsDir = import_node_path25.default.dirname(coreJsPath);
4896
+ const version2 = (0, import_shared45.getCoreJsVersion)(coreJsPath);
4897
+ const coreJsDir = import_node_path23.default.dirname(coreJsPath);
5110
4898
  swcConfig.env.coreJs = version2;
5111
4899
  if (polyfillMode === "usage") {
5112
4900
  swcConfig.env.shippedProposals = true;
@@ -5142,12 +4930,12 @@ function applySwcDecoratorConfig(swcConfig, config) {
5142
4930
  throw new Error("Unknown decorators version: ${version}");
5143
4931
  }
5144
4932
  }
5145
- var import_node_path25, import_shared47, builtinSwcLoaderName, pluginSwc;
4933
+ var import_node_path23, import_shared45, builtinSwcLoaderName, pluginSwc;
5146
4934
  var init_swc = __esm({
5147
4935
  "src/plugins/swc.ts"() {
5148
4936
  "use strict";
5149
- import_node_path25 = __toESM(require("path"));
5150
- import_shared47 = require("@rsbuild/shared");
4937
+ import_node_path23 = __toESM(require("path"));
4938
+ import_shared45 = require("@rsbuild/shared");
5151
4939
  init_constants();
5152
4940
  builtinSwcLoaderName = "builtin:swc-loader";
5153
4941
  pluginSwc = () => ({
@@ -5157,8 +4945,8 @@ var init_swc = __esm({
5157
4945
  order: "pre",
5158
4946
  handler: async (chain, { CHAIN_ID: CHAIN_ID3, target }) => {
5159
4947
  const config = api.getNormalizedConfig();
5160
- const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared47.SCRIPT_REGEX).type("javascript/auto");
5161
- (0, import_shared47.applyScriptCondition)({
4948
+ const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared45.SCRIPT_REGEX).type("javascript/auto");
4949
+ (0, import_shared45.applyScriptCondition)({
5162
4950
  rule,
5163
4951
  chain,
5164
4952
  config,
@@ -5176,10 +4964,10 @@ var init_swc = __esm({
5176
4964
  if (swcConfig.jsc?.externalHelpers) {
5177
4965
  chain.resolve.alias.set(
5178
4966
  "@swc/helpers",
5179
- import_node_path25.default.dirname(require.resolve("@swc/helpers/package.json"))
4967
+ import_node_path23.default.dirname(require.resolve("@swc/helpers/package.json"))
5180
4968
  );
5181
4969
  }
5182
- if ((0, import_shared47.isWebTarget)(target)) {
4970
+ if ((0, import_shared45.isWebTarget)(target)) {
5183
4971
  const polyfillMode = config.output.polyfill;
5184
4972
  if (polyfillMode === "off") {
5185
4973
  swcConfig.env.mode = void 0;
@@ -5188,15 +4976,15 @@ var init_swc = __esm({
5188
4976
  await applyCoreJs(swcConfig, chain, polyfillMode);
5189
4977
  }
5190
4978
  }
5191
- const mergedSwcConfig = (0, import_shared47.mergeChainedOptions)({
4979
+ const mergedSwcConfig = (0, import_shared45.mergeChainedOptions)({
5192
4980
  defaults: swcConfig,
5193
4981
  options: config.tools.swc,
5194
- mergeFn: import_shared47.deepmerge
4982
+ mergeFn: import_shared45.deepmerge
5195
4983
  });
5196
4984
  rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
5197
4985
  chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
5198
4986
  or: ["text/javascript", "application/javascript"]
5199
- }).resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared47.cloneDeep)(mergedSwcConfig));
4987
+ }).resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared45.cloneDeep)(mergedSwcConfig));
5200
4988
  }
5201
4989
  });
5202
4990
  }
@@ -5210,14 +4998,14 @@ __export(rspackProfile_exports, {
5210
4998
  pluginRspackProfile: () => pluginRspackProfile,
5211
4999
  stopProfiler: () => stopProfiler
5212
5000
  });
5213
- var import_node_inspector, import_node_path26, import_shared48, import_shared49, import_core8, stopProfiler, pluginRspackProfile;
5001
+ var import_node_inspector, import_node_path24, import_shared46, import_shared47, import_core8, stopProfiler, pluginRspackProfile;
5214
5002
  var init_rspackProfile = __esm({
5215
5003
  "src/plugins/rspackProfile.ts"() {
5216
5004
  "use strict";
5217
5005
  import_node_inspector = __toESM(require("inspector"));
5218
- import_node_path26 = __toESM(require("path"));
5219
- import_shared48 = require("@rsbuild/shared");
5220
- import_shared49 = require("@rsbuild/shared");
5006
+ import_node_path24 = __toESM(require("path"));
5007
+ import_shared46 = require("@rsbuild/shared");
5008
+ import_shared47 = require("@rsbuild/shared");
5221
5009
  import_core8 = require("@rspack/core");
5222
5010
  stopProfiler = (output, profileSession) => {
5223
5011
  if (!profileSession) {
@@ -5225,10 +5013,10 @@ var init_rspackProfile = __esm({
5225
5013
  }
5226
5014
  profileSession.post("Profiler.stop", (error, param) => {
5227
5015
  if (error) {
5228
- import_shared49.logger.error("Failed to generate JS CPU profile:", error);
5016
+ import_shared47.logger.error("Failed to generate JS CPU profile:", error);
5229
5017
  return;
5230
5018
  }
5231
- import_shared48.fse.writeFileSync(output, JSON.stringify(param.profile));
5019
+ import_shared46.fse.writeFileSync(output, JSON.stringify(param.profile));
5232
5020
  });
5233
5021
  };
5234
5022
  pluginRspackProfile = () => ({
@@ -5239,7 +5027,7 @@ var init_rspackProfile = __esm({
5239
5027
  return;
5240
5028
  }
5241
5029
  const timestamp = Date.now();
5242
- const profileDir = import_node_path26.default.join(
5030
+ const profileDir = import_node_path24.default.join(
5243
5031
  api.context.distPath,
5244
5032
  `rspack-profile-${timestamp}`
5245
5033
  );
@@ -5247,11 +5035,11 @@ var init_rspackProfile = __esm({
5247
5035
  const enableProfileTrace = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("TRACE");
5248
5036
  const enableCPUProfile = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("CPU");
5249
5037
  const enableLogging = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("LOGGING");
5250
- const traceFilePath = import_node_path26.default.join(profileDir, "trace.json");
5251
- const cpuProfilePath = import_node_path26.default.join(profileDir, "jscpuprofile.json");
5252
- const loggingFilePath = import_node_path26.default.join(profileDir, "logging.json");
5038
+ const traceFilePath = import_node_path24.default.join(profileDir, "trace.json");
5039
+ const cpuProfilePath = import_node_path24.default.join(profileDir, "jscpuprofile.json");
5040
+ const loggingFilePath = import_node_path24.default.join(profileDir, "logging.json");
5253
5041
  const onStart = () => {
5254
- import_shared48.fse.ensureDirSync(profileDir);
5042
+ import_shared46.fse.ensureDirSync(profileDir);
5255
5043
  if (enableProfileTrace) {
5256
5044
  import_core8.rspack.experimental_registerGlobalTrace(
5257
5045
  "trace",
@@ -5275,7 +5063,7 @@ var init_rspackProfile = __esm({
5275
5063
  logging: "verbose",
5276
5064
  loggingTrace: true
5277
5065
  });
5278
- import_shared48.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
5066
+ import_shared46.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
5279
5067
  }
5280
5068
  });
5281
5069
  api.onExit(() => {
@@ -5283,7 +5071,7 @@ var init_rspackProfile = __esm({
5283
5071
  import_core8.rspack.experimental_cleanupGlobalTrace();
5284
5072
  }
5285
5073
  stopProfiler(cpuProfilePath, profileSession);
5286
- import_shared49.logger.info(`Saved Rspack profile file to ${profileDir}`);
5074
+ import_shared47.logger.info(`Saved Rspack profile file to ${profileDir}`);
5287
5075
  });
5288
5076
  }
5289
5077
  });
@@ -5291,13 +5079,13 @@ var init_rspackProfile = __esm({
5291
5079
  });
5292
5080
 
5293
5081
  // src/server/middlewares.ts
5294
- var import_node_path27, import_node_url3, import_shared50, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
5082
+ var import_node_path25, import_node_url2, import_shared48, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
5295
5083
  var init_middlewares = __esm({
5296
5084
  "src/server/middlewares.ts"() {
5297
5085
  "use strict";
5298
- import_node_path27 = __toESM(require("path"));
5299
- import_node_url3 = require("url");
5300
- import_shared50 = require("@rsbuild/shared");
5086
+ import_node_path25 = __toESM(require("path"));
5087
+ import_node_url2 = require("url");
5088
+ import_shared48 = require("@rsbuild/shared");
5301
5089
  faviconFallbackMiddleware = (req, res, next) => {
5302
5090
  if (req.url === "/favicon.ico") {
5303
5091
  res.statusCode = 204;
@@ -5308,16 +5096,16 @@ var init_middlewares = __esm({
5308
5096
  };
5309
5097
  getStatusCodeColor = (status) => {
5310
5098
  if (status >= 500) {
5311
- return import_shared50.color.red;
5099
+ return import_shared48.color.red;
5312
5100
  }
5313
5101
  if (status >= 400) {
5314
- return import_shared50.color.yellow;
5102
+ return import_shared48.color.yellow;
5315
5103
  }
5316
5104
  if (status >= 300) {
5317
- return import_shared50.color.cyan;
5105
+ return import_shared48.color.cyan;
5318
5106
  }
5319
5107
  if (status >= 200) {
5320
- return import_shared50.color.green;
5108
+ return import_shared48.color.green;
5321
5109
  }
5322
5110
  return (res) => res;
5323
5111
  };
@@ -5332,8 +5120,8 @@ var init_middlewares = __esm({
5332
5120
  const statusColor = getStatusCodeColor(status);
5333
5121
  const endAt = process.hrtime();
5334
5122
  const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
5335
- (0, import_shared50.debug)(
5336
- `${statusColor(status)} ${method} ${import_shared50.color.gray(url2)} ${import_shared50.color.gray(
5123
+ (0, import_shared48.debug)(
5124
+ `${statusColor(status)} ${method} ${import_shared48.color.gray(url2)} ${import_shared48.color.gray(
5337
5125
  `${totalTime.toFixed(3)} ms`
5338
5126
  )}`
5339
5127
  );
@@ -5360,10 +5148,10 @@ var init_middlewares = __esm({
5360
5148
  const { url: url2 } = req;
5361
5149
  let pathname = url2;
5362
5150
  try {
5363
- pathname = (0, import_node_url3.parse)(url2, false, true).pathname;
5151
+ pathname = (0, import_node_url2.parse)(url2, false, true).pathname;
5364
5152
  } catch (err) {
5365
- import_shared50.logger.error(
5366
- new Error(`Invalid URL: ${import_shared50.color.yellow(url2)}`, { cause: err })
5153
+ import_shared48.logger.error(
5154
+ new Error(`Invalid URL: ${import_shared48.color.yellow(url2)}`, { cause: err })
5367
5155
  );
5368
5156
  return next();
5369
5157
  }
@@ -5375,10 +5163,10 @@ var init_middlewares = __esm({
5375
5163
  });
5376
5164
  };
5377
5165
  const rewrite = (newUrl, isFallback = false) => {
5378
- if (isFallback && (0, import_shared50.isDebug)()) {
5379
- (0, import_shared50.debug)(
5380
- `${req.method} ${import_shared50.color.gray(
5381
- `${req.url} ${import_shared50.color.yellow("fallback")} to ${newUrl}`
5166
+ if (isFallback && (0, import_shared48.isDebug)()) {
5167
+ (0, import_shared48.debug)(
5168
+ `${req.method} ${import_shared48.color.gray(
5169
+ `${req.url} ${import_shared48.color.yellow("fallback")} to ${newUrl}`
5382
5170
  )}`
5383
5171
  );
5384
5172
  }
@@ -5392,7 +5180,7 @@ var init_middlewares = __esm({
5392
5180
  };
5393
5181
  if (pathname.endsWith("/")) {
5394
5182
  const newUrl = `${pathname}index.html`;
5395
- const filePath = import_node_path27.default.join(distPath, pathname, "index.html");
5183
+ const filePath = import_node_path25.default.join(distPath, pathname, "index.html");
5396
5184
  if (await isFileExists2(filePath)) {
5397
5185
  return rewrite(newUrl);
5398
5186
  }
@@ -5401,13 +5189,13 @@ var init_middlewares = __esm({
5401
5189
  !pathname.endsWith(".html")
5402
5190
  ) {
5403
5191
  const newUrl = `${pathname}.html`;
5404
- const filePath = import_node_path27.default.join(distPath, `${pathname}.html`);
5192
+ const filePath = import_node_path25.default.join(distPath, `${pathname}.html`);
5405
5193
  if (await isFileExists2(filePath)) {
5406
5194
  return rewrite(newUrl);
5407
5195
  }
5408
5196
  }
5409
5197
  if (htmlFallback === "index") {
5410
- if (await isFileExists2(import_node_path27.default.join(distPath, "index.html"))) {
5198
+ if (await isFileExists2(import_node_path25.default.join(distPath, "index.html"))) {
5411
5199
  return rewrite("/index.html", true);
5412
5200
  }
5413
5201
  }
@@ -5444,17 +5232,17 @@ function formatProxyOptions(proxyOptions) {
5444
5232
  ret.push(opts);
5445
5233
  }
5446
5234
  }
5447
- const handleError = (err) => import_shared51.logger.error(err);
5235
+ const handleError = (err) => import_shared49.logger.error(err);
5448
5236
  for (const opts of ret) {
5449
5237
  opts.onError ?? (opts.onError = handleError);
5450
5238
  }
5451
5239
  return ret;
5452
5240
  }
5453
- var import_shared51, import_http_proxy_middleware, createProxyMiddleware;
5241
+ var import_shared49, import_http_proxy_middleware, createProxyMiddleware;
5454
5242
  var init_proxy = __esm({
5455
5243
  "src/server/proxy.ts"() {
5456
5244
  "use strict";
5457
- import_shared51 = require("@rsbuild/shared");
5245
+ import_shared49 = require("@rsbuild/shared");
5458
5246
  import_http_proxy_middleware = require("@rsbuild/shared/http-proxy-middleware");
5459
5247
  createProxyMiddleware = (proxyOptions) => {
5460
5248
  const formattedOptionsList = formatProxyOptions(proxyOptions);
@@ -5495,13 +5283,13 @@ var init_proxy = __esm({
5495
5283
  });
5496
5284
 
5497
5285
  // src/server/getDevMiddlewares.ts
5498
- var import_node_path28, import_node_url4, import_shared52, applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
5286
+ var import_node_path26, import_node_url3, import_shared50, applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
5499
5287
  var init_getDevMiddlewares = __esm({
5500
5288
  "src/server/getDevMiddlewares.ts"() {
5501
5289
  "use strict";
5502
- import_node_path28 = require("path");
5503
- import_node_url4 = __toESM(require("url"));
5504
- import_shared52 = require("@rsbuild/shared");
5290
+ import_node_path26 = require("path");
5291
+ import_node_url3 = __toESM(require("url"));
5292
+ import_shared50 = require("@rsbuild/shared");
5505
5293
  init_middlewares();
5506
5294
  applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
5507
5295
  const setupMiddlewares = dev.setupMiddlewares || [];
@@ -5541,8 +5329,8 @@ var init_getDevMiddlewares = __esm({
5541
5329
  }
5542
5330
  middlewares.push((req, res, next) => {
5543
5331
  res.setHeader("Access-Control-Allow-Origin", "*");
5544
- const path15 = req.url ? import_node_url4.default.parse(req.url).pathname : "";
5545
- if (path15?.includes("hot-update")) {
5332
+ const path13 = req.url ? import_node_url3.default.parse(req.url).pathname : "";
5333
+ if (path13?.includes("hot-update")) {
5546
5334
  res.setHeader("Access-Control-Allow-Credentials", "false");
5547
5335
  }
5548
5336
  const confHeaders = server.headers;
@@ -5582,7 +5370,7 @@ var init_getDevMiddlewares = __esm({
5582
5370
  if (server.publicDir !== false && server.publicDir?.name) {
5583
5371
  const { default: sirv2 } = await import("../compiled/sirv/index.js");
5584
5372
  const { name } = server.publicDir;
5585
- const publicDir = (0, import_node_path28.isAbsolute)(name) ? name : (0, import_node_path28.join)(pwd, name);
5373
+ const publicDir = (0, import_node_path26.isAbsolute)(name) ? name : (0, import_node_path26.join)(pwd, name);
5586
5374
  const assetMiddleware = sirv2(publicDir, {
5587
5375
  etag: true,
5588
5376
  dev: true
@@ -5592,7 +5380,7 @@ var init_getDevMiddlewares = __esm({
5592
5380
  const { distPath } = output;
5593
5381
  compileMiddlewareAPI && middlewares.push(
5594
5382
  getHtmlFallbackMiddleware({
5595
- distPath: (0, import_node_path28.isAbsolute)(distPath) ? distPath : (0, import_node_path28.join)(pwd, distPath),
5383
+ distPath: (0, import_node_path26.isAbsolute)(distPath) ? distPath : (0, import_node_path26.join)(pwd, distPath),
5596
5384
  callback: compileMiddlewareAPI.middleware,
5597
5385
  htmlFallback: server.htmlFallback,
5598
5386
  outputFileSystem
@@ -5618,7 +5406,7 @@ var init_getDevMiddlewares = __esm({
5618
5406
  getMiddlewares = async (options) => {
5619
5407
  const middlewares = [];
5620
5408
  const { compileMiddlewareAPI } = options;
5621
- if ((0, import_shared52.isDebug)()) {
5409
+ if ((0, import_shared50.isDebug)()) {
5622
5410
  middlewares.push(await getRequestLoggerMiddleware());
5623
5411
  }
5624
5412
  const { before, after } = applySetupMiddlewares(
@@ -5646,8 +5434,8 @@ var init_getDevMiddlewares = __esm({
5646
5434
  function getURLMessages(urls, routes) {
5647
5435
  if (routes.length === 1) {
5648
5436
  return urls.map(
5649
- ({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${import_shared53.color.cyan(
5650
- (0, import_shared53.normalizeUrl)(`${url2}${routes[0].pathname}`)
5437
+ ({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${import_shared51.color.cyan(
5438
+ (0, import_shared51.normalizeUrl)(`${url2}${routes[0].pathname}`)
5651
5439
  )}
5652
5440
  `
5653
5441
  ).join("");
@@ -5661,9 +5449,9 @@ function getURLMessages(urls, routes) {
5661
5449
  message += ` ${`> ${label}`}
5662
5450
  `;
5663
5451
  for (const r of routes) {
5664
- message += ` ${import_shared53.color.dim("-")} ${import_shared53.color.dim(
5452
+ message += ` ${import_shared51.color.dim("-")} ${import_shared51.color.dim(
5665
5453
  r.entryName.padEnd(maxNameLength + 4)
5666
- )}${import_shared53.color.cyan((0, import_shared53.normalizeUrl)(`${url2}${r.pathname}`))}
5454
+ )}${import_shared51.color.cyan((0, import_shared51.normalizeUrl)(`${url2}${r.pathname}`))}
5667
5455
  `;
5668
5456
  }
5669
5457
  });
@@ -5680,7 +5468,7 @@ function printServerURLs({
5680
5468
  return;
5681
5469
  }
5682
5470
  let urls = originalUrls;
5683
- if ((0, import_shared53.isFunction)(printUrls)) {
5471
+ if ((0, import_shared51.isFunction)(printUrls)) {
5684
5472
  const newUrls = printUrls({
5685
5473
  urls: urls.map((item) => item.url),
5686
5474
  port,
@@ -5704,17 +5492,17 @@ function printServerURLs({
5704
5492
  return;
5705
5493
  }
5706
5494
  const message = getURLMessages(urls, routes);
5707
- import_shared53.logger.log(message);
5495
+ import_shared51.logger.log(message);
5708
5496
  return message;
5709
5497
  }
5710
- var import_node_net, import_node_net2, import_node_os, import_shared53, formatPrefix, formatRoutes, HMR_SOCK_PATH, mergeDevOptions, getPort, getServerOptions, getDevOptions, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
5498
+ var import_node_net, import_node_net2, import_node_os, import_shared51, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
5711
5499
  var init_helper = __esm({
5712
5500
  "src/server/helper.ts"() {
5713
5501
  "use strict";
5714
5502
  import_node_net = __toESM(require("net"));
5715
5503
  import_node_net2 = require("net");
5716
5504
  import_node_os = __toESM(require("os"));
5717
- import_shared53 = require("@rsbuild/shared");
5505
+ import_shared51 = require("@rsbuild/shared");
5718
5506
  formatPrefix = (prefix) => {
5719
5507
  if (!prefix) {
5720
5508
  return "/";
@@ -5735,25 +5523,6 @@ var init_helper = __esm({
5735
5523
  }).sort((a) => a.entryName === "index" ? -1 : 1);
5736
5524
  };
5737
5525
  HMR_SOCK_PATH = "/rsbuild-hmr";
5738
- mergeDevOptions = ({
5739
- rsbuildConfig,
5740
- port
5741
- }) => {
5742
- const defaultDevConfig = {
5743
- client: {
5744
- path: HMR_SOCK_PATH,
5745
- port: port.toString(),
5746
- // By default it is set to "location.hostname"
5747
- host: "",
5748
- // By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
5749
- protocol: void 0
5750
- },
5751
- writeToDisk: false,
5752
- liveReload: true
5753
- };
5754
- const devConfig = rsbuildConfig.dev ? (0, import_shared53.deepmerge)(defaultDevConfig, rsbuildConfig.dev) : defaultDevConfig;
5755
- return devConfig;
5756
- };
5757
5526
  getPort = async ({
5758
5527
  host,
5759
5528
  port,
@@ -5796,46 +5565,46 @@ var init_helper = __esm({
5796
5565
  );
5797
5566
  }
5798
5567
  if (!silent) {
5799
- import_shared53.logger.info(
5800
- `Port ${original} is in use, ${import_shared53.color.yellow(`using port ${port}.`)}
5568
+ import_shared51.logger.info(
5569
+ `Port ${original} is in use, ${import_shared51.color.yellow(`using port ${port}.`)}
5801
5570
  `
5802
5571
  );
5803
5572
  }
5804
5573
  }
5805
5574
  return port;
5806
5575
  };
5807
- getServerOptions = async ({
5808
- rsbuildConfig,
5576
+ getServerConfig = async ({
5577
+ config,
5809
5578
  getPortSilently
5810
5579
  }) => {
5811
- const host = rsbuildConfig.server?.host || import_shared53.DEFAULT_DEV_HOST;
5580
+ const host = config.server.host || import_shared51.DEFAULT_DEV_HOST;
5812
5581
  const port = await getPort({
5813
5582
  host,
5814
- port: rsbuildConfig.server?.port || import_shared53.DEFAULT_PORT,
5815
- strictPort: rsbuildConfig.server?.strictPort || false,
5583
+ port: config.server.port || import_shared51.DEFAULT_PORT,
5584
+ strictPort: config.server.strictPort || false,
5816
5585
  silent: getPortSilently
5817
5586
  });
5818
- const https = Boolean(rsbuildConfig.server?.https) || false;
5819
- return { port, host, https, serverConfig: rsbuildConfig.server || {} };
5587
+ const https = Boolean(config.server.https) || false;
5588
+ return { port, host, https };
5820
5589
  };
5821
- getDevOptions = async ({
5822
- rsbuildConfig,
5823
- getPortSilently
5590
+ getDevConfig = ({
5591
+ config,
5592
+ port
5824
5593
  }) => {
5825
- const { port, host, https, serverConfig } = await getServerOptions({
5826
- rsbuildConfig,
5827
- getPortSilently
5828
- });
5829
- const devConfig = mergeDevOptions({ rsbuildConfig, port });
5830
- const liveReload = devConfig.liveReload;
5831
- return {
5832
- devConfig,
5833
- serverConfig,
5834
- port,
5835
- host,
5836
- https,
5837
- liveReload
5594
+ const defaultDevConfig = {
5595
+ client: {
5596
+ path: HMR_SOCK_PATH,
5597
+ port: port.toString(),
5598
+ // By default it is set to "location.hostname"
5599
+ host: "",
5600
+ // By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
5601
+ protocol: void 0
5602
+ },
5603
+ writeToDisk: false,
5604
+ liveReload: true
5838
5605
  };
5606
+ const devConfig = config.dev ? (0, import_shared51.deepmerge)(defaultDevConfig, config.dev) : defaultDevConfig;
5607
+ return devConfig;
5839
5608
  };
5840
5609
  getIpv4Interfaces = () => {
5841
5610
  const interfaces = import_node_os.default.networkInterfaces();
@@ -5885,7 +5654,7 @@ var init_helper = __esm({
5885
5654
  port,
5886
5655
  host
5887
5656
  }) => {
5888
- if (host && host !== import_shared53.DEFAULT_DEV_HOST) {
5657
+ if (host && host !== import_shared51.DEFAULT_DEV_HOST) {
5889
5658
  return [
5890
5659
  {
5891
5660
  label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
@@ -5999,11 +5768,11 @@ var init_watchFiles = __esm({
5999
5768
  });
6000
5769
 
6001
5770
  // src/server/socketServer.ts
6002
- var import_shared54, import_ws, SocketServer;
5771
+ var import_shared52, import_ws, SocketServer;
6003
5772
  var init_socketServer = __esm({
6004
5773
  "src/server/socketServer.ts"() {
6005
5774
  "use strict";
6006
- import_shared54 = require("@rsbuild/shared");
5775
+ import_shared52 = require("@rsbuild/shared");
6007
5776
  import_ws = __toESM(require("../compiled/ws/index.js"));
6008
5777
  init_helpers();
6009
5778
  SocketServer = class {
@@ -6030,7 +5799,7 @@ var init_socketServer = __esm({
6030
5799
  path: this.options.client?.path
6031
5800
  });
6032
5801
  this.wsServer.on("error", (err) => {
6033
- import_shared54.logger.error(err);
5802
+ import_shared52.logger.error(err);
6034
5803
  });
6035
5804
  this.timer = setInterval(() => {
6036
5805
  for (const socket of this.wsServer.clients) {
@@ -6246,24 +6015,28 @@ var devServer_exports = {};
6246
6015
  __export(devServer_exports, {
6247
6016
  createDevServer: () => createDevServer
6248
6017
  });
6249
- async function createDevServer(options, createDevMiddleware2, {
6018
+ async function createDevServer(options, createDevMiddleware2, config, {
6250
6019
  compiler: customCompiler,
6251
6020
  getPortSilently,
6252
6021
  runCompile = true
6253
6022
  } = {}) {
6254
- if (!(0, import_shared55.getNodeEnv)()) {
6255
- (0, import_shared55.setNodeEnv)("development");
6023
+ if (!(0, import_shared53.getNodeEnv)()) {
6024
+ (0, import_shared53.setNodeEnv)("development");
6256
6025
  }
6257
- (0, import_shared55.debug)("create dev server");
6258
- const rsbuildConfig = options.context.config;
6259
- const { devConfig, serverConfig, port, host, https } = await getDevOptions({
6260
- rsbuildConfig,
6026
+ (0, import_shared53.debug)("create dev server");
6027
+ const serverConfig = config.server;
6028
+ const { port, host, https } = await getServerConfig({
6029
+ config,
6261
6030
  getPortSilently
6262
6031
  });
6032
+ const devConfig = getDevConfig({
6033
+ config,
6034
+ port
6035
+ });
6263
6036
  const routes = formatRoutes(
6264
6037
  options.context.entry,
6265
- rsbuildConfig.output?.distPath?.html,
6266
- rsbuildConfig.html?.outputStructure
6038
+ config.output.distPath.html,
6039
+ config.html.outputStructure
6267
6040
  );
6268
6041
  options.context.devServer = {
6269
6042
  hostname: host,
@@ -6277,7 +6050,7 @@ async function createDevServer(options, createDevMiddleware2, {
6277
6050
  customCompiler
6278
6051
  );
6279
6052
  const { CompilerDevMiddleware: CompilerDevMiddleware2 } = await Promise.resolve().then(() => (init_compilerDevMiddleware(), compilerDevMiddleware_exports));
6280
- const publicPaths = (0, import_shared55.isMultiCompiler)(compiler) ? compiler.compilers.map(import_shared55.getPublicPathFromCompiler) : [(0, import_shared55.getPublicPathFromCompiler)(compiler)];
6053
+ const publicPaths = (0, import_shared53.isMultiCompiler)(compiler) ? compiler.compilers.map(import_shared53.getPublicPathFromCompiler) : [(0, import_shared53.getPublicPathFromCompiler)(compiler)];
6281
6054
  const compilerDevMiddleware = new CompilerDevMiddleware2({
6282
6055
  dev: devConfig,
6283
6056
  server: serverConfig,
@@ -6285,7 +6058,7 @@ async function createDevServer(options, createDevMiddleware2, {
6285
6058
  devMiddleware
6286
6059
  });
6287
6060
  compilerDevMiddleware.init();
6288
- outputFileSystem = ((0, import_shared55.isMultiCompiler)(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || import_node_fs4.default;
6061
+ outputFileSystem = ((0, import_shared53.isMultiCompiler)(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || import_node_fs4.default;
6289
6062
  return {
6290
6063
  middleware: compilerDevMiddleware.middleware,
6291
6064
  sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
@@ -6327,7 +6100,7 @@ async function createDevServer(options, createDevMiddleware2, {
6327
6100
  dev: devConfig,
6328
6101
  server: serverConfig,
6329
6102
  output: {
6330
- distPath: rsbuildConfig.output?.distPath?.root || import_shared55.ROOT_DIST_DIR
6103
+ distPath: config.output.distPath.root || import_shared53.ROOT_DIST_DIR
6331
6104
  },
6332
6105
  outputFileSystem
6333
6106
  });
@@ -6348,7 +6121,7 @@ async function createDevServer(options, createDevMiddleware2, {
6348
6121
  https: serverConfig.https,
6349
6122
  middlewares
6350
6123
  });
6351
- (0, import_shared55.debug)("listen dev server");
6124
+ (0, import_shared53.debug)("listen dev server");
6352
6125
  return new Promise((resolve) => {
6353
6126
  httpServer.listen(
6354
6127
  {
@@ -6361,7 +6134,7 @@ async function createDevServer(options, createDevMiddleware2, {
6361
6134
  }
6362
6135
  middlewares.use(notFoundMiddleware);
6363
6136
  httpServer.on("upgrade", devMiddlewares.onUpgrade);
6364
- (0, import_shared55.debug)("listen dev server done");
6137
+ (0, import_shared53.debug)("listen dev server done");
6365
6138
  await server.afterListen();
6366
6139
  const closeServer = async () => {
6367
6140
  await server.close();
@@ -6392,15 +6165,15 @@ async function createDevServer(options, createDevMiddleware2, {
6392
6165
  await fileWatcher?.close();
6393
6166
  }
6394
6167
  };
6395
- (0, import_shared55.debug)("create dev server done");
6168
+ (0, import_shared53.debug)("create dev server done");
6396
6169
  return server;
6397
6170
  }
6398
- var import_node_fs4, import_shared55, import_connect;
6171
+ var import_node_fs4, import_shared53, import_connect;
6399
6172
  var init_devServer = __esm({
6400
6173
  "src/server/devServer.ts"() {
6401
6174
  "use strict";
6402
6175
  import_node_fs4 = __toESM(require("fs"));
6403
- import_shared55 = require("@rsbuild/shared");
6176
+ import_shared53 = require("@rsbuild/shared");
6404
6177
  import_connect = __toESM(require("@rsbuild/shared/connect"));
6405
6178
  init_getDevMiddlewares();
6406
6179
  init_helper();
@@ -6417,19 +6190,20 @@ __export(prodServer_exports, {
6417
6190
  RsbuildProdServer: () => RsbuildProdServer,
6418
6191
  startProdServer: () => startProdServer
6419
6192
  });
6420
- async function startProdServer(context, rsbuildConfig, { getPortSilently } = {}) {
6421
- if (!(0, import_shared56.getNodeEnv)()) {
6422
- (0, import_shared56.setNodeEnv)("production");
6193
+ async function startProdServer(context, config, { getPortSilently } = {}) {
6194
+ if (!(0, import_shared54.getNodeEnv)()) {
6195
+ (0, import_shared54.setNodeEnv)("production");
6423
6196
  }
6424
- const { serverConfig, port, host, https } = await getServerOptions({
6425
- rsbuildConfig,
6197
+ const { port, host, https } = await getServerConfig({
6198
+ config,
6426
6199
  getPortSilently
6427
6200
  });
6201
+ const serverConfig = config.server;
6428
6202
  const server = new RsbuildProdServer({
6429
6203
  pwd: context.rootPath,
6430
6204
  output: {
6431
- path: rsbuildConfig.output?.distPath?.root || import_shared56.ROOT_DIST_DIR,
6432
- assetPrefix: rsbuildConfig.output?.assetPrefix
6205
+ path: config.output.distPath.root || import_shared54.ROOT_DIST_DIR,
6206
+ assetPrefix: config.output.assetPrefix
6433
6207
  },
6434
6208
  serverConfig
6435
6209
  });
@@ -6448,8 +6222,8 @@ async function startProdServer(context, rsbuildConfig, { getPortSilently } = {})
6448
6222
  async () => {
6449
6223
  const routes = formatRoutes(
6450
6224
  context.entry,
6451
- rsbuildConfig.output?.distPath?.html,
6452
- rsbuildConfig.html?.outputStructure
6225
+ config.output.distPath.html,
6226
+ config.html.outputStructure
6453
6227
  );
6454
6228
  await context.hooks.onAfterStartProdServer.call({
6455
6229
  port,
@@ -6481,12 +6255,12 @@ async function startProdServer(context, rsbuildConfig, { getPortSilently } = {})
6481
6255
  );
6482
6256
  });
6483
6257
  }
6484
- var import_node_path29, import_shared56, import_connect2, import_sirv, RsbuildProdServer;
6258
+ var import_node_path27, import_shared54, import_connect2, import_sirv, RsbuildProdServer;
6485
6259
  var init_prodServer = __esm({
6486
6260
  "src/server/prodServer.ts"() {
6487
6261
  "use strict";
6488
- import_node_path29 = require("path");
6489
- import_shared56 = require("@rsbuild/shared");
6262
+ import_node_path27 = require("path");
6263
+ import_shared54 = require("@rsbuild/shared");
6490
6264
  import_connect2 = __toESM(require("@rsbuild/shared/connect"));
6491
6265
  import_sirv = __toESM(require("../compiled/sirv/index.js"));
6492
6266
  init_helper();
@@ -6506,7 +6280,7 @@ var init_prodServer = __esm({
6506
6280
  }
6507
6281
  async applyDefaultMiddlewares() {
6508
6282
  const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
6509
- if ((0, import_shared56.isDebug)()) {
6283
+ if ((0, import_shared54.isDebug)()) {
6510
6284
  this.middlewares.use(await getRequestLoggerMiddleware());
6511
6285
  }
6512
6286
  if (compress) {
@@ -6547,11 +6321,11 @@ var init_prodServer = __esm({
6547
6321
  }
6548
6322
  applyStaticAssetMiddleware() {
6549
6323
  const {
6550
- output: { path: path15, assetPrefix },
6324
+ output: { path: path13, assetPrefix },
6551
6325
  serverConfig: { htmlFallback },
6552
6326
  pwd
6553
6327
  } = this.options;
6554
- const assetMiddleware = (0, import_sirv.default)((0, import_node_path29.join)(pwd, path15), {
6328
+ const assetMiddleware = (0, import_sirv.default)((0, import_node_path27.join)(pwd, path13), {
6555
6329
  etag: true,
6556
6330
  dev: true,
6557
6331
  ignores: ["favicon.ico"],
@@ -6581,17 +6355,17 @@ var build_exports = {};
6581
6355
  __export(build_exports, {
6582
6356
  build: () => build
6583
6357
  });
6584
- var import_shared57, import_core9, build;
6358
+ var import_shared55, import_core9, build;
6585
6359
  var init_build = __esm({
6586
6360
  "src/provider/build.ts"() {
6587
6361
  "use strict";
6588
- import_shared57 = require("@rsbuild/shared");
6362
+ import_shared55 = require("@rsbuild/shared");
6589
6363
  import_core9 = require("@rspack/core");
6590
6364
  init_createCompiler();
6591
6365
  init_initConfigs();
6592
6366
  build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
6593
- if (!(0, import_shared57.getNodeEnv)()) {
6594
- (0, import_shared57.setNodeEnv)(mode);
6367
+ if (!(0, import_shared55.getNodeEnv)()) {
6368
+ (0, import_shared55.setNodeEnv)(mode);
6595
6369
  }
6596
6370
  const { context } = initOptions;
6597
6371
  let compiler;
@@ -6615,7 +6389,7 @@ var init_build = __esm({
6615
6389
  isFirstCompile = false;
6616
6390
  await p;
6617
6391
  };
6618
- (0, import_shared57.onCompileDone)(
6392
+ (0, import_shared55.onCompileDone)(
6619
6393
  compiler,
6620
6394
  onDone,
6621
6395
  // @ts-expect-error type mismatch
@@ -6624,7 +6398,7 @@ var init_build = __esm({
6624
6398
  if (watch) {
6625
6399
  compiler.watch({}, (err) => {
6626
6400
  if (err) {
6627
- import_shared57.logger.error(err);
6401
+ import_shared55.logger.error(err);
6628
6402
  }
6629
6403
  });
6630
6404
  return;
@@ -6650,11 +6424,11 @@ var provider_exports = {};
6650
6424
  __export(provider_exports, {
6651
6425
  rspackProvider: () => rspackProvider
6652
6426
  });
6653
- var import_shared58, rspackProvider;
6427
+ var import_shared56, rspackProvider;
6654
6428
  var init_provider = __esm({
6655
6429
  "src/provider/provider.ts"() {
6656
6430
  "use strict";
6657
- import_shared58 = require("@rsbuild/shared");
6431
+ import_shared56 = require("@rsbuild/shared");
6658
6432
  init_createContext();
6659
6433
  init_initPlugins();
6660
6434
  init_plugins();
@@ -6663,7 +6437,7 @@ var init_provider = __esm({
6663
6437
  pluginManager,
6664
6438
  rsbuildOptions
6665
6439
  }) => {
6666
- const rsbuildConfig = (0, import_shared58.pickRsbuildConfig)(rsbuildOptions.rsbuildConfig);
6440
+ const rsbuildConfig = (0, import_shared56.pickRsbuildConfig)(rsbuildOptions.rsbuildConfig);
6667
6441
  const context = await createContext(rsbuildOptions, rsbuildConfig, "rspack");
6668
6442
  const pluginAPI = getPluginAPI({ context, pluginManager });
6669
6443
  context.pluginAPI = pluginAPI;
@@ -6705,8 +6479,6 @@ var init_provider = __esm({
6705
6479
  plugins.nodeAddons(),
6706
6480
  plugins.define(),
6707
6481
  plugins.css(),
6708
- plugins.less(),
6709
- plugins.sass(),
6710
6482
  Promise.resolve().then(() => (init_minimize(), minimize_exports)).then((m) => m.pluginMinimize()),
6711
6483
  Promise.resolve().then(() => (init_progress(), progress_exports)).then((m) => m.pluginProgress()),
6712
6484
  Promise.resolve().then(() => (init_swc(), swc_exports)).then((m) => m.pluginSwc()),
@@ -6728,28 +6500,30 @@ var init_provider = __esm({
6728
6500
  async createDevServer(options) {
6729
6501
  const { createDevServer: createDevServer2 } = await Promise.resolve().then(() => (init_devServer(), devServer_exports));
6730
6502
  const { createDevMiddleware: createDevMiddleware2 } = await Promise.resolve().then(() => (init_createCompiler(), createCompiler_exports));
6731
- await initRsbuildConfig({ context, pluginManager });
6503
+ const config = await initRsbuildConfig({ context, pluginManager });
6732
6504
  return createDevServer2(
6733
6505
  { context, pluginManager, rsbuildOptions },
6734
6506
  createDevMiddleware2,
6507
+ config,
6735
6508
  options
6736
6509
  );
6737
6510
  },
6738
6511
  async startDevServer(options) {
6739
6512
  const { createDevServer: createDevServer2 } = await Promise.resolve().then(() => (init_devServer(), devServer_exports));
6740
6513
  const { createDevMiddleware: createDevMiddleware2 } = await Promise.resolve().then(() => (init_createCompiler(), createCompiler_exports));
6741
- await initRsbuildConfig({ context, pluginManager });
6514
+ const config = await initRsbuildConfig({ context, pluginManager });
6742
6515
  const server = await createDevServer2(
6743
6516
  { context, pluginManager, rsbuildOptions },
6744
6517
  createDevMiddleware2,
6518
+ config,
6745
6519
  options
6746
6520
  );
6747
6521
  return server.listen();
6748
6522
  },
6749
6523
  async preview(options) {
6750
6524
  const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
6751
- await initRsbuildConfig({ context, pluginManager });
6752
- return startProdServer2(context, context.config, options);
6525
+ const config = await initRsbuildConfig({ context, pluginManager });
6526
+ return startProdServer2(context, config, options);
6753
6527
  },
6754
6528
  async build(options) {
6755
6529
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
@@ -6806,17 +6580,17 @@ async function createRsbuild(options = {}) {
6806
6580
  pluginManager,
6807
6581
  rsbuildOptions
6808
6582
  });
6809
- (0, import_shared59.debug)("add default plugins");
6583
+ (0, import_shared57.debug)("add default plugins");
6810
6584
  await applyDefaultPlugins(pluginManager);
6811
- (0, import_shared59.debug)("add default plugins done");
6585
+ (0, import_shared57.debug)("add default plugins done");
6812
6586
  const rsbuild = {
6813
- ...(0, import_shared59.pick)(pluginManager, [
6587
+ ...(0, import_shared57.pick)(pluginManager, [
6814
6588
  "addPlugins",
6815
6589
  "getPlugins",
6816
6590
  "removePlugins",
6817
6591
  "isPluginExists"
6818
6592
  ]),
6819
- ...(0, import_shared59.pick)(pluginAPI, [
6593
+ ...(0, import_shared57.pick)(pluginAPI, [
6820
6594
  "onBeforeBuild",
6821
6595
  "onBeforeCreateCompiler",
6822
6596
  "onBeforeStartDevServer",
@@ -6847,11 +6621,11 @@ async function createRsbuild(options = {}) {
6847
6621
  }
6848
6622
  return rsbuild;
6849
6623
  }
6850
- var import_shared59, getRspackProvider;
6624
+ var import_shared57, getRspackProvider;
6851
6625
  var init_createRsbuild = __esm({
6852
6626
  "src/createRsbuild.ts"() {
6853
6627
  "use strict";
6854
- import_shared59 = require("@rsbuild/shared");
6628
+ import_shared57 = require("@rsbuild/shared");
6855
6629
  init_pluginManager();
6856
6630
  getRspackProvider = async () => {
6857
6631
  const { rspackProvider: rspackProvider2 } = await Promise.resolve().then(() => (init_provider(), provider_exports));
@@ -6874,7 +6648,7 @@ async function init({
6874
6648
  cwd: root,
6875
6649
  mode: cliOptions?.envMode
6876
6650
  });
6877
- if ((0, import_shared60.isDev)()) {
6651
+ if ((0, import_shared58.isDev)()) {
6878
6652
  onBeforeRestartServer(envs.cleanup);
6879
6653
  }
6880
6654
  const { content: config, filePath: configFilePath } = await loadConfig({
@@ -6914,17 +6688,17 @@ async function init({
6914
6688
  });
6915
6689
  } catch (err) {
6916
6690
  if (isRestart) {
6917
- import_shared60.logger.error(err);
6691
+ import_shared58.logger.error(err);
6918
6692
  } else {
6919
6693
  throw err;
6920
6694
  }
6921
6695
  }
6922
6696
  }
6923
- var import_shared60, commonOpts;
6697
+ var import_shared58, commonOpts;
6924
6698
  var init_init = __esm({
6925
6699
  "src/cli/init.ts"() {
6926
6700
  "use strict";
6927
- import_shared60 = require("@rsbuild/shared");
6701
+ import_shared58 = require("@rsbuild/shared");
6928
6702
  init_config();
6929
6703
  init_loadEnv();
6930
6704
  init_restart();
@@ -6945,7 +6719,7 @@ __export(src_exports, {
6945
6719
  defineConfig: () => defineConfig,
6946
6720
  loadConfig: () => loadConfig,
6947
6721
  loadEnv: () => loadEnv,
6948
- logger: () => import_shared63.logger,
6722
+ logger: () => import_shared61.logger,
6949
6723
  mergeRsbuildConfig: () => mergeRsbuildConfig,
6950
6724
  rspack: () => import_core10.rspack,
6951
6725
  version: () => version
@@ -6982,8 +6756,8 @@ __export(internal_exports, {
6982
6756
 
6983
6757
  // src/cli/commands.ts
6984
6758
  var import_node_fs5 = require("fs");
6985
- var import_node_path30 = require("path");
6986
- var import_shared61 = require("@rsbuild/shared");
6759
+ var import_node_path28 = require("path");
6760
+ var import_shared59 = require("@rsbuild/shared");
6987
6761
  var import_commander = require("../compiled/commander/index.js");
6988
6762
  init_init();
6989
6763
  var applyCommonOptions = (command) => {
@@ -6999,7 +6773,7 @@ var applyServerOptions = (command) => {
6999
6773
  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");
7000
6774
  };
7001
6775
  function runCli() {
7002
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.0-beta.6");
6776
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.0-beta.7");
7003
6777
  const devCommand = import_commander.program.command("dev");
7004
6778
  const buildCommand = import_commander.program.command("build");
7005
6779
  const previewCommand = import_commander.program.command("preview");
@@ -7013,8 +6787,8 @@ function runCli() {
7013
6787
  const rsbuild = await init({ cliOptions: options });
7014
6788
  await rsbuild?.startDevServer();
7015
6789
  } catch (err) {
7016
- import_shared61.logger.error("Failed to start dev server.");
7017
- import_shared61.logger.error(err);
6790
+ import_shared59.logger.error("Failed to start dev server.");
6791
+ import_shared59.logger.error(err);
7018
6792
  process.exit(1);
7019
6793
  }
7020
6794
  });
@@ -7025,8 +6799,8 @@ function runCli() {
7025
6799
  watch: options.watch
7026
6800
  });
7027
6801
  } catch (err) {
7028
- import_shared61.logger.error("Failed to build.");
7029
- import_shared61.logger.error(err);
6802
+ import_shared59.logger.error("Failed to build.");
6803
+ import_shared59.logger.error(err);
7030
6804
  process.exit(1);
7031
6805
  }
7032
6806
  });
@@ -7035,15 +6809,15 @@ function runCli() {
7035
6809
  const rsbuild = await init({ cliOptions: options });
7036
6810
  if (rsbuild && !(0, import_node_fs5.existsSync)(rsbuild.context.distPath)) {
7037
6811
  throw new Error(
7038
- `The output directory ${import_shared61.color.yellow(
6812
+ `The output directory ${import_shared59.color.yellow(
7039
6813
  rsbuild.context.distPath
7040
6814
  )} does not exist, please build the project before previewing.`
7041
6815
  );
7042
6816
  }
7043
6817
  await rsbuild?.preview();
7044
6818
  } catch (err) {
7045
- import_shared61.logger.error("Failed to start preview server.");
7046
- import_shared61.logger.error(err);
6819
+ import_shared59.logger.error("Failed to start preview server.");
6820
+ import_shared59.logger.error(err);
7047
6821
  process.exit(1);
7048
6822
  }
7049
6823
  });
@@ -7053,12 +6827,12 @@ function runCli() {
7053
6827
  await rsbuild?.inspectConfig({
7054
6828
  env: options.env,
7055
6829
  verbose: options.verbose,
7056
- outputPath: (0, import_node_path30.join)(rsbuild.context.distPath, options.output),
6830
+ outputPath: (0, import_node_path28.join)(rsbuild.context.distPath, options.output),
7057
6831
  writeToDisk: true
7058
6832
  });
7059
6833
  } catch (err) {
7060
- import_shared61.logger.error("Failed to inspect config.");
7061
- import_shared61.logger.error(err);
6834
+ import_shared59.logger.error("Failed to inspect config.");
6835
+ import_shared59.logger.error(err);
7062
6836
  process.exit(1);
7063
6837
  }
7064
6838
  });
@@ -7066,7 +6840,7 @@ function runCli() {
7066
6840
  }
7067
6841
 
7068
6842
  // src/cli/prepare.ts
7069
- var import_shared62 = require("@rsbuild/shared");
6843
+ var import_shared60 = require("@rsbuild/shared");
7070
6844
  function initNodeEnv() {
7071
6845
  if (!process.env.NODE_ENV) {
7072
6846
  const command = process.argv[2];
@@ -7079,7 +6853,7 @@ function prepareCli() {
7079
6853
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7080
6854
  console.log();
7081
6855
  }
7082
- import_shared62.logger.greet(` ${`Rsbuild v${"0.7.0-beta.6"}`}
6856
+ import_shared60.logger.greet(` ${`Rsbuild v${"0.7.0-beta.7"}`}
7083
6857
  `);
7084
6858
  }
7085
6859
 
@@ -7108,10 +6882,10 @@ init_plugins();
7108
6882
  init_loadEnv();
7109
6883
  init_createRsbuild();
7110
6884
  init_config();
7111
- var import_shared63 = require("@rsbuild/shared");
6885
+ var import_shared61 = require("@rsbuild/shared");
7112
6886
  init_mergeConfig();
7113
6887
  init_constants();
7114
- var version = "0.7.0-beta.6";
6888
+ var version = "0.7.0-beta.7";
7115
6889
  // Annotate the CommonJS export names for ESM import in node:
7116
6890
  0 && (module.exports = {
7117
6891
  PLUGIN_CSS_NAME,