* Get a string for Vite's printServerUrls function without actually printing it. * Allows us to set `task.output` to that value without having to pass a custom logger into Vite. * @see https://github.com/vitejs/vite/blob/42233d39674be808a6a1a79f1a6e44ed23ba0d61/packages/vite/src/node/logger.ts#L16
(urls: vite.ResolvedServerUrls)
| 424 | * @see https://github.com/vitejs/vite/blob/42233d39674be808a6a1a79f1a6e44ed23ba0d61/packages/vite/src/node/logger.ts#L168-L188 |
| 425 | */ |
| 426 | function getServerURLs(urls: vite.ResolvedServerUrls) { |
| 427 | let output = ''; |
| 428 | const colorUrl = (url: string) => |
| 429 | chalk.cyan(url.replace(/:(\d+)\//, (_, port) => `:${chalk.bold(port)}/`)); |
| 430 | for (const url of urls.local) { |
| 431 | output += ` ${chalk.green('➜')} ${chalk.bold('Local')}: ${colorUrl(url)}`; |
| 432 | } |
| 433 | for (const url of urls.network) { |
| 434 | output += ` \n${chalk.green('➜')} ${chalk.bold('Network')}: ${colorUrl(url)}`; |
| 435 | } |
| 436 | if (urls.network.length === 0) { |
| 437 | output += |
| 438 | chalk.dim(` \n${chalk.green('➜')} ${chalk.bold('Network')}: use `) + |
| 439 | chalk.bold('--host') + |
| 440 | chalk.dim(' to expose'); |
| 441 | } |
| 442 | |
| 443 | return output; |
| 444 | } |
| 445 | |
| 446 | export { VitePlugin }; |