Skip to content

Commit 11fd021

Browse files
egoettelmanndgp1130
authored andcommittedJan 12, 2022
fix(@angular-devkit/build-angular): websocket client only injected if required
After the webpack-dev-server migration to v4, the websocket client was always injected, even if not required. This caused unnecessary 'ws' requests when live-reload and hmr were disabled. (cherry picked from commit 50167a3)
1 parent 92b4e06 commit 11fd021

File tree

1 file changed

+35
-15
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+35
-15
lines changed
 

‎packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts

+35-15
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ export async function getDevServerConfig(
5151
});
5252
}
5353

54-
const webSocketPath = posix.join(servePath, 'ws');
55-
5654
return {
5755
plugins: extraPlugins,
5856
module: {
@@ -76,11 +74,6 @@ export async function getDevServerConfig(
7674
},
7775
],
7876
},
79-
webSocketServer: {
80-
options: {
81-
path: webSocketPath,
82-
},
83-
},
8477
compress: false,
8578
static: false,
8679
server: getServerConfig(root, wco.buildOptions),
@@ -92,14 +85,7 @@ export async function getDevServerConfig(
9285
liveReload,
9386
hot: hmr && !liveReload ? 'only' : hmr,
9487
proxy: await addProxyConfig(root, proxyConfig),
95-
client: {
96-
logging: 'info',
97-
webSocketURL: getPublicHostOptions(wco.buildOptions, webSocketPath),
98-
overlay: {
99-
errors: true,
100-
warnings: false,
101-
},
102-
},
88+
...getWebSocketSettings(wco.buildOptions, servePath),
10389
},
10490
};
10591
}
@@ -297,6 +283,40 @@ function getAllowedHostsConfig(
297283
return undefined;
298284
}
299285

286+
function getWebSocketSettings(
287+
options: WebpackDevServerOptions,
288+
servePath: string,
289+
): {
290+
webSocketServer?: DevServerConfiguration['webSocketServer'];
291+
client?: DevServerConfiguration['client'];
292+
} {
293+
const { hmr, liveReload } = options;
294+
if (!hmr && !liveReload) {
295+
return {
296+
webSocketServer: false,
297+
client: undefined,
298+
};
299+
}
300+
301+
const webSocketPath = posix.join(servePath, 'ws');
302+
303+
return {
304+
webSocketServer: {
305+
options: {
306+
path: webSocketPath,
307+
},
308+
},
309+
client: {
310+
logging: 'info',
311+
webSocketURL: getPublicHostOptions(options, webSocketPath),
312+
overlay: {
313+
errors: true,
314+
warnings: false,
315+
},
316+
},
317+
};
318+
}
319+
300320
function getPublicHostOptions(options: WebpackDevServerOptions, webSocketPath: string): string {
301321
let publicHost: string | null | undefined = options.publicHost;
302322
if (publicHost) {

0 commit comments

Comments
 (0)
Please sign in to comment.