Skip to content

Commit 8c76cb2

Browse files
committed
fix(@angular-devkit/build-angular): media files download files in vite
Unlike assets, output file were not prefixed with a `/`. This change alings these and now files are always prefixed with a slash. Closes #26215
1 parent 5990875 commit 8c76cb2

File tree

1 file changed

+8
-9
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+8
-9
lines changed

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ function analyzeResultFiles(
315315
// This mimics the Webpack dev-server behavior.
316316
filePath = '/index.html';
317317
} else {
318-
filePath = normalizePath(file.path);
318+
filePath = '/' + normalizePath(file.path);
319319
}
320+
320321
seen.add(filePath);
321322

322323
// Skip analysis of sourcemaps
@@ -458,21 +459,19 @@ export async function setupServer(
458459
// Remove query if present
459460
const [importerFile] = importer.split('?', 1);
460461

461-
source = normalizePath(
462-
join(dirname(relative(virtualProjectRoot, importerFile)), source),
463-
);
464-
}
465-
if (source[0] === '/') {
466-
source = source.slice(1);
462+
source =
463+
'/' +
464+
normalizePath(join(dirname(relative(virtualProjectRoot, importerFile)), source));
467465
}
466+
468467
const [file] = source.split('?', 1);
469468
if (outputFiles.has(file)) {
470469
return join(virtualProjectRoot, source);
471470
}
472471
},
473472
load(id) {
474473
const [file] = id.split('?', 1);
475-
const relativeFile = normalizePath(relative(virtualProjectRoot, file));
474+
const relativeFile = '/' + normalizePath(relative(virtualProjectRoot, file));
476475
const codeContents = outputFiles.get(relativeFile)?.contents;
477476
if (codeContents === undefined) {
478477
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
@@ -590,7 +589,7 @@ export async function setupServer(
590589
return;
591590
}
592591

593-
const rawHtml = outputFiles.get('index.server.html')?.contents;
592+
const rawHtml = outputFiles.get('/index.server.html')?.contents;
594593
if (!rawHtml) {
595594
next();
596595

0 commit comments

Comments
 (0)