Skip to content

Commit b86bb08

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular/build): disable dev-server websocket when live reload is disabled
When live reload is disabled (`"liveReload": false`/`no-live-reload`) within the development server, the Vite websocket server will no longer be initialized. Additionally, the client code will not be loaded by the browser. This allows the development server to be used in test scenarios that would prefer to more fully represent the production fielded configuration such as E2E testing or other forms of browser-based testing. (cherry picked from commit 4633562)
1 parent fed31e0 commit b86bb08

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/angular/build/src/builders/dev-server/vite-server.ts

+3
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ export async function setupServer(
651651
host: serverOptions.host,
652652
open: serverOptions.open,
653653
headers: serverOptions.headers,
654+
// Disable the websocket if live reload is disabled (false/undefined are the only valid values)
655+
ws: serverOptions.liveReload === false && serverOptions.hmr === false ? false : undefined,
654656
proxy,
655657
cors: {
656658
// Allow preflight requests to be proxied.
@@ -711,6 +713,7 @@ export async function setupServer(
711713
virtualProjectRoot,
712714
outputFiles,
713715
external: externalMetadata.explicitBrowser,
716+
skipViteClient: serverOptions.liveReload === false && serverOptions.hmr === false,
714717
}),
715718
],
716719
// Browser only optimizeDeps. (This does not run for SSR dependencies).

packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface AngularMemoryPluginOptions {
1717
virtualProjectRoot: string;
1818
outputFiles: AngularMemoryOutputFiles;
1919
external?: string[];
20+
skipViteClient?: boolean;
2021
}
2122

2223
export async function createAngularMemoryPlugin(
@@ -55,9 +56,11 @@ export async function createAngularMemoryPlugin(
5556
const relativeFile = '/' + normalizePath(relative(virtualProjectRoot, file));
5657
const codeContents = outputFiles.get(relativeFile)?.contents;
5758
if (codeContents === undefined) {
58-
return relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')
59-
? loadViteClientCode(file)
60-
: undefined;
59+
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
60+
return options.skipViteClient ? '' : loadViteClientCode(file);
61+
}
62+
63+
return undefined;
6164
}
6265

6366
const code = Buffer.from(codeContents).toString('utf-8');

0 commit comments

Comments
 (0)