Skip to content

Commit 1b3b16a

Browse files
committed
fix(serve): do not default port in devServer v4
1 parent 90f2548 commit 1b3b16a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/serve/src/startDevServer.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,21 @@ export default function startDevServer(compiler, devServerArgs): object[] {
3939
devServerOptions.forEach((devServerOpts): void => {
4040
const options = mergeOptions(cliOptions, devServerOpts);
4141
options.host = options.host || 'localhost';
42-
options.port = options.port || 8080;
42+
// devSever v4 handles the default port itself
43+
if (!isDevServer4) {
44+
options.port = options.port || 8080;
45+
}
4346

44-
const portNum = +options.port;
47+
if (options.port) {
48+
const portNum = +options.port;
4549

46-
if (usedPorts.find((port) => portNum === port)) {
47-
throw new Error(
48-
'Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.',
49-
);
50+
if (usedPorts.find((port) => portNum === port)) {
51+
throw new Error(
52+
'Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.',
53+
);
54+
}
55+
usedPorts.push(portNum);
5056
}
51-
usedPorts.push(portNum);
5257

5358
const server = new Server(compiler, options);
5459
server.listen(options.port, options.host, (err): void => {

0 commit comments

Comments
 (0)