Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): websocket client only injected if…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
egoettelmann authored and dgp1130 committed Jan 12, 2022
1 parent 92b4e06 commit 11fd021
Showing 1 changed file with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export async function getDevServerConfig(
});
}

const webSocketPath = posix.join(servePath, 'ws');

return {
plugins: extraPlugins,
module: {
Expand All @@ -76,11 +74,6 @@ export async function getDevServerConfig(
},
],
},
webSocketServer: {
options: {
path: webSocketPath,
},
},
compress: false,
static: false,
server: getServerConfig(root, wco.buildOptions),
Expand All @@ -92,14 +85,7 @@ export async function getDevServerConfig(
liveReload,
hot: hmr && !liveReload ? 'only' : hmr,
proxy: await addProxyConfig(root, proxyConfig),
client: {
logging: 'info',
webSocketURL: getPublicHostOptions(wco.buildOptions, webSocketPath),
overlay: {
errors: true,
warnings: false,
},
},
...getWebSocketSettings(wco.buildOptions, servePath),
},
};
}
Expand Down Expand Up @@ -297,6 +283,40 @@ function getAllowedHostsConfig(
return undefined;
}

function getWebSocketSettings(
options: WebpackDevServerOptions,
servePath: string,
): {
webSocketServer?: DevServerConfiguration['webSocketServer'];
client?: DevServerConfiguration['client'];
} {
const { hmr, liveReload } = options;
if (!hmr && !liveReload) {
return {
webSocketServer: false,
client: undefined,
};
}

const webSocketPath = posix.join(servePath, 'ws');

return {
webSocketServer: {
options: {
path: webSocketPath,
},
},
client: {
logging: 'info',
webSocketURL: getPublicHostOptions(options, webSocketPath),
overlay: {
errors: true,
warnings: false,
},
},
};
}

function getPublicHostOptions(options: WebpackDevServerOptions, webSocketPath: string): string {
let publicHost: string | null | undefined = options.publicHost;
if (publicHost) {
Expand Down

0 comments on commit 11fd021

Please sign in to comment.