From d6c919cbcf2fee7b5f32fe960f69f6d9e37739fe Mon Sep 17 00:00:00 2001 From: Avichal Trivedi Date: Mon, 2 Dec 2024 13:44:38 +0530 Subject: [PATCH] added server url logging at the end --- lib/Server.js | 30 ++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 31 insertions(+) diff --git a/lib/Server.js b/lib/Server.js index 22b0a5ebd2..535be401bb 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -2870,6 +2870,29 @@ class Server { const useColor = getColorsOption(this.getCompilerOptions()); const server = /** @type {S} */ (this.server); + const logServerUrls = () => { + const protocol = this.isTlsServer ? "https" : "http"; + const { address, port } = + /** @type {import("net").AddressInfo} */ (server.address()); + + const prettyPrintURL = (hostname) => + url.format({ protocol, hostname, port, pathname: "/" }); + + const localhost = prettyPrintURL("localhost"); + const networkIPv4 = Server.findIp("v4", false) + ? prettyPrintURL(Server.findIp("v4", false)) + : null; + + this.logger.info(`Project is running at:`); + + if (localhost) { + this.logger.info(`- Local: ${colors.info(useColor, localhost)}`); + } + + if (networkIPv4) { + this.logger.info(`- On Your Network: ${colors.info(useColor, networkIPv4)}`); + } + }; if (this.options.ipc) { this.logger.info(`Project is running at: "${server.address()}"`); @@ -2962,6 +2985,8 @@ class Server { loopbacks.push([colors.info(useColor, localhost)]); } + + if (loopbackIPv4) { loopbacks.push([colors.info(useColor, loopbackIPv4)]); } @@ -2979,12 +3004,17 @@ class Server { ); } + this.compiler.hooks.done.tap("LogServerUrlsPlugin", () => { + logServerUrls(); + }); + if (networkUrlIPv6) { this.logger.info( `On Your Network (IPv6): ${colors.info(useColor, networkUrlIPv6)}`, ); } + if (/** @type {NormalizedOpen[]} */ (this.options.open).length > 0) { const openTarget = prettyPrintURL( !this.options.host || diff --git a/package.json b/package.json index 303fe81cd2..e31df1dcde 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "node": ">= 18.12.0" }, "scripts": { + "start":"webpack serve --config webpack.config.js", "fmt:check": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different", "lint:prettier": "prettier --cache --list-different .", "lint:js": "eslint --cache .",