Skip to content

Commit 449e21b

Browse files
committed
fix(@angular-devkit/build-angular): correctly load dev server assets with vite 4.4.0+
The underlying development server (Vite) for the application build system updated its static file serving dependencies which resulted in the `@fs` special file URLs supported by Vite to have a different format. Previously, the paths were encoded using `encodeURIComponent` but are now use `encodeURI`. The development server integration with Vite will now use the matching encoding to allow build defined assets to be correctly served.
1 parent 636ed54 commit 449e21b

File tree

2 files changed

+11
-3
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server
  • tests/legacy-cli/e2e/tests/basic

2 files changed

+11
-3
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ export async function setupServer(
286286
// Rewrite all build assets to a vite raw fs URL
287287
const assetSourcePath = assets.get(pathname);
288288
if (assetSourcePath !== undefined) {
289-
req.url = `/@fs/${encodeURIComponent(assetSourcePath)}`;
289+
// The encoding needs to match what happens in the vite static middleware.
290+
// ref: https://github.com/vitejs/vite/blob/d4f13bd81468961c8c926438e815ab6b1c82735e/packages/vite/src/node/server/middlewares/static.ts#L163
291+
req.url = `/@fs/${encodeURI(assetSourcePath)}`;
290292
next();
291293

292294
return;

Diff for: tests/legacy-cli/e2e/tests/basic/serve.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ export default async function () {
1818
}
1919

2020
async function verifyResponse(port: number): Promise<void> {
21-
const response = await fetch(`http://localhost:${port}/`);
21+
const indexResponse = await fetch(`http://localhost:${port}/`);
2222

23-
if (!/<app-root><\/app-root>/.test(await response.text())) {
23+
if (!/<app-root><\/app-root>/.test(await indexResponse.text())) {
2424
throw new Error('Response does not match expected value.');
2525
}
26+
27+
const assetResponse = await fetch(`http://localhost:${port}/favicon.ico`);
28+
29+
if (!assetResponse.ok) {
30+
throw new Error('Expected favicon asset to be available.');
31+
}
2632
}

0 commit comments

Comments
 (0)