@4399ywkf/core 5.1.2 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2127,7 +2127,7 @@ var defaultConfig = {
2127
2127
  strictMode: true,
2128
2128
  dev: {
2129
2129
  port: 3e3,
2130
- host: "localhost",
2130
+ host: "127.0.0.1",
2131
2131
  proxy: {},
2132
2132
  https: false
2133
2133
  },
@@ -4172,6 +4172,10 @@ function getNetworkAddress(port) {
4172
4172
  }
4173
4173
  return null;
4174
4174
  }
4175
+ function displayHost(host) {
4176
+ if (host === "0.0.0.0" || host === "::") return "localhost";
4177
+ return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
4178
+ }
4175
4179
  var BAR_WIDTH = 30;
4176
4180
  function renderBar(percent) {
4177
4181
  const filled = Math.round(BAR_WIDTH * percent);
@@ -4273,7 +4277,7 @@ var DevPrinter = class {
4273
4277
  * 打印服务器信息面板(dev 模式使用)
4274
4278
  */
4275
4279
  printServerInfo() {
4276
- const localUrl = `http://localhost:${this.port}/`;
4280
+ const localUrl = `http://${displayHost(this._host)}:${this.port}/`;
4277
4281
  const networkUrl = getNetworkAddress(this.port);
4278
4282
  console.log(` ${chalk.bold(">")} Local: ${chalk.cyan(localUrl)}`);
4279
4283
  if (networkUrl) {
@@ -4316,7 +4320,7 @@ function registerShortcuts(getPrinter, opts) {
4316
4320
  getPrinter().printShortcuts();
4317
4321
  break;
4318
4322
  case "o": {
4319
- const url = `http://localhost:${opts.getPort()}/`;
4323
+ const url = `http://${displayHost(opts.getHost())}:${opts.getPort()}/`;
4320
4324
  import("child_process").then((cp) => {
4321
4325
  const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
4322
4326
  cp.exec(`${command} ${url}`);
@@ -4389,7 +4393,7 @@ async function build(options = {}) {
4389
4393
  let rspackConfig = createRspackConfig(config, cwd, { isDev: false });
4390
4394
  rspackConfig = await pluginManager.applyRspackConfigHooks(rspackConfig);
4391
4395
  const pluginNames = pluginManager.getPluginNames();
4392
- const printer = new DevPrinter("localhost", 0, pluginNames, true);
4396
+ const printer = new DevPrinter("127.0.0.1", 0, pluginNames, true);
4393
4397
  printer.printBanner();
4394
4398
  printer.printBuildStart();
4395
4399
  printer.updateProgress(0, "preparing");
@@ -4542,7 +4546,7 @@ async function startDevServer(cwd, config) {
4542
4546
  await pluginManager.runBeforeDevServer();
4543
4547
  let rspackConfig = createRspackConfig(config, cwd, { isDev: true });
4544
4548
  rspackConfig = await pluginManager.applyRspackConfigHooks(rspackConfig);
4545
- const host = config.dev.host || "localhost";
4549
+ const host = config.dev.host || "127.0.0.1";
4546
4550
  const preferredPort = config.dev.port || 3e3;
4547
4551
  const port = await getAvailablePort(preferredPort, host);
4548
4552
  const pluginNames = pluginManager.getPluginNames();
@@ -4625,6 +4629,7 @@ async function dev(options = {}) {
4625
4629
  };
4626
4630
  registerShortcuts(() => current.printer, {
4627
4631
  getPort: () => current.port,
4632
+ getHost: () => current.host,
4628
4633
  onQuit: async () => {
4629
4634
  console.log(chalk3.gray("\n Shutting down...\n"));
4630
4635
  await shutdown();