fix: register files generated by Vite plugins in static file cache (#3534)

Fixes #3487 

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
fry69
2026-03-29 20:04:46 +00:00
committed by GitHub
co-authored by Bartek Iwańczuk Claude Opus 4.6
parent 400e217c5e
commit 8b0d42b82a
6 changed files with 145 additions and 1 deletions
@@ -318,6 +318,47 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
}
}
}
// Scan client output directory for any additional files generated
// by Vite plugins (e.g., vite-plugin-pwa generates sw.js,
// manifest.webmanifest) that aren't in the Vite manifest or
// public directory.
if (await fsAdapter.isDirectory(clientOutDir)) {
// Normalize registered pathnames (strip leading /) for comparison
const registeredPaths = new Set(
staticFiles.map((f) =>
f.pathname.startsWith("/") ? f.pathname.slice(1) : f.pathname
),
);
const clientFiles = await fsAdapter.walk(
clientOutDir,
{
followSymlinks: false,
includeDirs: false,
includeFiles: true,
},
);
for await (const entry of clientFiles) {
const relative = path.relative(clientOutDir, entry.path);
// Skip .vite directory and already-registered files
if (
relative.startsWith(".vite/") ||
relative === ".vite" ||
registeredPaths.has(relative)
) {
continue;
}
staticFiles.push({
filePath: entry.path,
hash: null,
pathname: relative,
});
}
}
}
const code = await generateSnapshotServer({