diff --git a/packages/serve/src/startDevServer.ts b/packages/serve/src/startDevServer.ts index 8cbe238de76..d0b9116b702 100644 --- a/packages/serve/src/startDevServer.ts +++ b/packages/serve/src/startDevServer.ts @@ -11,21 +11,25 @@ import Server from 'webpack-dev-server/lib/Server'; */ export default function startDevServer(compiler, options): void { const firstWpOpt = compiler.compilers ? compiler.compilers[0].options : compiler.options; - const devServerOptions = firstWpOpt.devServer || {}; + let devServerOptions = firstWpOpt.devServer || {}; + + // set default host and port + devServerOptions = { host: 'localhost', port: 8080, ...devServerOptions }; - const host = options.host || devServerOptions.host || 'localhost'; - const port = options.port || devServerOptions.port || 8080; // socket should not have a default value, because it should only be used if the // user explicitly provides it const socket = options.socket || devServerOptions.socket; - options.host = host; - options.port = port; if (socket) { options.socket = socket; } - const server = new Server(compiler, options); + // Compose config from the CLI and devServer object from webpack config + const serverConfig = { ...options, ...devServerOptions }; + + const { host, port } = serverConfig; + + const server = new Server(compiler, serverConfig); server.listen(socket || port, host, (err): void => { if (err) { throw err;