Skip to content
Merged
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 @@ -443,6 +443,10 @@ export async function setupServer(
const relativeFile = normalizePath(path.relative(virtualProjectRoot, file));
const codeContents = outputFiles.get(relativeFile)?.contents;
if (codeContents === undefined) {
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
return loadViteClientCode(file);
}

return;
}

Expand Down Expand Up @@ -683,6 +687,28 @@ export async function setupServer(
return configuration;
}

/**
* Reads the resolved Vite client code from disk and updates the content to remove
* an unactionable suggestion to update the Vite configuration file to disable the
* error overlay. The Vite configuration file is not present when used in the Angular
* CLI.
* @param file The absolute path to the Vite client code.
* @returns
*/
async function loadViteClientCode(file: string) {
const originalContents = await readFile(file, 'utf-8');
let contents = originalContents.replace('You can also disable this overlay by setting', '');
contents = contents.replace(
// eslint-disable-next-line max-len
'<code part="config-option-name">server.hmr.overlay</code> to <code part="config-option-value">false</code> in <code part="config-file-name">vite.config.js.</code>',
'',
);

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

return contents;
}

function pathnameWithoutServePath(url: string, serverOptions: NormalizedDevServerOptions): string {
const parsedUrl = new URL(url, 'http://localhost');
let pathname = decodeURIComponent(parsedUrl.pathname);
Expand Down