@respond-run/manifest
Version:
Minimal utility for loading Vite's manifest.json in Cloudflare Workers and other edge environments
34 lines (33 loc) • 927 B
JavaScript
let cachedManifest = null;
/**
* Load and cache Vite manifest from a Cloudflare-compatible asset binding.
*/
export async function getManifest(fetchAsset) {
if (cachedManifest)
return cachedManifest;
try {
const res = await fetchAsset('/.vite/manifest.json');
if (res.ok) {
cachedManifest = await res.json();
return cachedManifest;
}
}
catch {
// Silent fail in dev mode
}
return null;
}
/**
* Resolves the script/style paths for the main client entrypoint.
*/
export async function getClientEntry(fetchAsset) {
const fallback = { scriptPath: '/src/client.ts' };
const manifest = await getManifest(fetchAsset);
const entry = manifest?.['src/client.ts'];
if (!entry)
return fallback;
return {
scriptPath: '/' + entry.file,
stylePath: entry.css?.[0] ? '/' + entry.css[0] : undefined,
};
}