From 23a028e1643b7c594cfae9dca7de35fab3b31608 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 21 Apr 2021 00:15:25 +0300 Subject: [PATCH] fix: avoid unnecessary searching port --- packages/serve/src/startDevServer.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/serve/src/startDevServer.ts b/packages/serve/src/startDevServer.ts index 1d99e5027e8..e1d7e2fb9aa 100644 --- a/packages/serve/src/startDevServer.ts +++ b/packages/serve/src/startDevServer.ts @@ -21,15 +21,13 @@ export default async function startDevServer( cliOptions: any, logger: any, ): Promise[]> { - let devServerVersion, Server, findPort; + let devServerVersion, Server; try { // eslint-disable-next-line node/no-extraneous-require devServerVersion = require('webpack-dev-server/package.json').version; // eslint-disable-next-line node/no-extraneous-require Server = require('webpack-dev-server/lib/Server'); - // eslint-disable-next-line node/no-extraneous-require - findPort = require('webpack-dev-server/lib/utils/findPort'); } catch (err) { logger.error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`); process.exit(2); @@ -71,9 +69,7 @@ export default async function startDevServer( for (const compilerWithDevServerOption of compilersWithDevServerOption) { const options = mergeOptions(compilerWithDevServerOption.options.devServer || {}, devServerCliOptions); - if (isDevServer4) { - options.port = await findPort(options.port); - } else { + if (!isDevServer4) { const getPublicPathOption = (): string => { const normalizePublicPath = (publicPath): string => typeof publicPath === 'undefined' || publicPath === 'auto' ? '/' : publicPath; @@ -87,11 +83,6 @@ export default async function startDevServer( return normalizePublicPath(options.publicPath); } - // webpack-dev-server@4 - if (options.dev && options.dev.publicPath) { - return normalizePublicPath(options.dev.publicPath); - } - return normalizePublicPath(compilerWithDevServerOption.options.output.publicPath); }; const getStatsOption = (): string | boolean => {