Vite plugin that automatically adds <link rel="prefetch"> tags to HTML output for all JavaScript chunks bundled in Vite builds. Current version 0.0.4 (beta, infrequent releases). The plugin scans the output directory for bundles, filters map files and legacy builds, then injects prefetch links into the final index.html. It addresses a gap where Vite's built-in preload only handles initial page loads, not prefetching for later navigation. Differentiates from similar tools like vite-plugin-prefetch by being minimal and focused on bundle-based prefetching. Works only with Vite; no support for rollup standalone or custom SSR pipelines.
npm install vite-plugin-bundle-prefetchVerified import paths — ran on the pinned version, not inferred.
Minimal Vite config adding prefetch for all built JavaScript chunks, excluding source maps and legacy bundles.
Run vite build to see prefetch links in output HTML.
Provide excludeFn to skip .map files and legacy builds: excludeFn: (name) => name.includes('.map') || name.includes('legacy')Manually ensure no other prefetch links are added, or use transformIndexHtml hook to deduplicate.
Change vite.config.js extension to .mjs or add type: 'module' in package.json, then use import prefetchPlugin from 'vite-plugin-bundle-prefetch'
Use default import: import prefetchPlugin from 'vite-plugin-bundle-prefetch' (no curly braces)