Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ export async function setupServer(
outputFiles,
templateUpdates,
external: externalMetadata.explicitBrowser,
skipViteClient: serverOptions.liveReload === false && serverOptions.hmr === false,
disableViteTransport: !serverOptions.liveReload,
}),
],
// Browser only optimizeDeps. (This does not run for SSR dependencies).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface AngularMemoryPluginOptions {
outputFiles: AngularMemoryOutputFiles;
templateUpdates?: ReadonlyMap<string, string>;
external?: string[];
skipViteClient?: boolean;
disableViteTransport?: boolean;
}

const ANGULAR_PREFIX = '/@ng/';
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function createAngularMemoryPlugin(
const codeContents = outputFiles.get(relativeFile)?.contents;
if (codeContents === undefined) {
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
return options.skipViteClient ? '' : loadViteClientCode(file);
return loadViteClientCode(file, options.disableViteTransport);
}

return undefined;
Expand All @@ -118,9 +118,9 @@ export async function createAngularMemoryPlugin(
* @param file The absolute path to the Vite client code.
* @returns
*/
async function loadViteClientCode(file: string): Promise<string> {
async function loadViteClientCode(file: string, disableViteTransport = false): Promise<string> {
const originalContents = await readFile(file, 'utf-8');
const updatedContents = originalContents.replace(
let updatedContents = originalContents.replace(
`"You can also disable this overlay by setting ",
h("code", { part: "config-option-name" }, "server.hmr.overlay"),
" to ",
Expand All @@ -133,5 +133,17 @@ async function loadViteClientCode(file: string): Promise<string> {

assert(originalContents !== updatedContents, 'Failed to update Vite client error overlay text.');

if (disableViteTransport) {
const previousUpdatedContents = updatedContents;

updatedContents = updatedContents.replace('transport.connect(handleMessage)', '');
assert(
previousUpdatedContents !== updatedContents,
'Failed to update Vite client WebSocket disable.',
);

updatedContents = updatedContents.replace('console.debug("[vite] connecting...")', '');
}

return updatedContents;
}
Loading