Skip to content

Commit 2f1b650

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): remove unactionable error overlay suggestion from Vite-based dev server
The Vite-based development server that is used with the esbuild-based builders (`application`/`browser-esbuild`) will show an error overlay when the application build encounters an error. This overlay previously provided a suggestion to edit the `vite.config.js` configuration file to disable the error overlay. Since Vite usage is encapsulated within the Angular CLI, this suggestion is unactionable and may lead to user confusion due to no Vite configuration file being present within the project nor would creating one have an effect on the build process.
1 parent f4aebf5 commit 2f1b650

File tree

1 file changed

+26
-0
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+26
-0
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

+26
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ export async function setupServer(
443443
const relativeFile = normalizePath(path.relative(virtualProjectRoot, file));
444444
const codeContents = outputFiles.get(relativeFile)?.contents;
445445
if (codeContents === undefined) {
446+
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
447+
return loadViteClientCode(file);
448+
}
449+
446450
return;
447451
}
448452

@@ -683,6 +687,28 @@ export async function setupServer(
683687
return configuration;
684688
}
685689

690+
/**
691+
* Reads the resolved Vite client code from disk and updates the content to remove
692+
* an unactionable suggestion to update the Vite configuration file to disable the
693+
* error overlay. The Vite configuration file is not present when used in the Angular
694+
* CLI.
695+
* @param file The absolute path to the Vite client code.
696+
* @returns
697+
*/
698+
async function loadViteClientCode(file: string) {
699+
const originalContents = await readFile(file, 'utf-8');
700+
let contents = originalContents.replace('You can also disable this overlay by setting', '');
701+
contents = contents.replace(
702+
// eslint-disable-next-line max-len
703+
'<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>',
704+
'',
705+
);
706+
707+
assert(originalContents !== contents, 'Failed to update Vite client error overlay text.');
708+
709+
return contents;
710+
}
711+
686712
function pathnameWithoutServePath(url: string, serverOptions: NormalizedDevServerOptions): string {
687713
const parsedUrl = new URL(url, 'http://localhost');
688714
let pathname = decodeURIComponent(parsedUrl.pathname);

0 commit comments

Comments
 (0)