Skip to content

Commit 5a214b5

Browse files
committed
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.
1 parent f66933e commit 5a214b5

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ export async function setupServer(
650650
host: serverOptions.host,
651651
open: serverOptions.open,
652652
headers: serverOptions.headers,
653+
// Disable the websocket if live reload is disabled (false/undefined are the only valid values)
654+
ws: serverOptions.liveReload === false && serverOptions.hmr === false ? false : undefined,
653655
proxy,
654656
cors: {
655657
// Allow preflight requests to be proxied.
@@ -710,6 +712,7 @@ export async function setupServer(
710712
virtualProjectRoot,
711713
outputFiles,
712714
external: externalMetadata.explicitBrowser,
715+
skipViteClient: serverOptions.liveReload === false && serverOptions.hmr === false,
713716
}),
714717
],
715718
// Browser only optimizeDeps. (This does not run for SSR dependencies).

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

Lines changed: 6 additions & 3 deletions
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(
@@ -63,9 +64,11 @@ export async function createAngularMemoryPlugin(
6364
const relativeFile = '/' + normalizePath(relative(virtualProjectRoot, file));
6465
const codeContents = outputFiles.get(relativeFile)?.contents;
6566
if (codeContents === undefined) {
66-
return relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')
67-
? loadViteClientCode(file)
68-
: undefined;
67+
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
68+
return options.skipViteClient ? '' : loadViteClientCode(file);
69+
}
70+
71+
return undefined;
6972
}
7073

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

0 commit comments

Comments
 (0)