Skip to content

Commit 9efcb32

Browse files
committed
fix(@angular-devkit/build-webpack): better handle concurrent dev-servers
Webpack-dev-server doesn't handle concurrency very well. When using port 0, and 2 processes start at the same time, they end up being given the same port. The main reason for the issue is that it find a free port, put only uses at a later stage.
1 parent 13b9f7f commit 9efcb32

File tree

1 file changed

+7
-0
lines changed
  • packages/angular_devkit/build_webpack/src/webpack-dev-server

1 file changed

+7
-0
lines changed

packages/angular_devkit/build_webpack/src/webpack-dev-server/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export function runWebpackDevServer(
5858
return new WebpackDevServer(config, webpack);
5959
};
6060

61+
// Force `WEBPACK_DEV_SERVER_BASE_PORT` to use port 0 as base port.
62+
// This is needed to handle better concurrent dev-servers. Otherwise if two or more processes starts at the same time
63+
// they will end up being assigned the same port due to a race condition between the time you get the port number and
64+
// you actually start using it.
65+
// https://github.com/webpack/webpack-dev-server/blob/2b1208dadfbe70246a36b74954e3f2fd2c3ba220/lib/Server.js#L76-L94
66+
process.env.WEBPACK_DEV_SERVER_BASE_PORT = '0';
67+
6168
const log: WebpackLoggingCallback =
6269
options.logging || ((stats, config) => context.logger.info(stats.toString(config.stats)));
6370

0 commit comments

Comments
 (0)