Registry / web-framework / vite-preload

vite-preload

JSON →
library1.0.5jsnpmunverified

Vite plugin (v1.0.6) that preloads server-rendered lazy React components and their CSS to eliminate FOUC and reduce load times. Unlike vite-plugin-preload, it evaluates used modules at render time (not build time). Supports Vite 5-8 and React 18-19. Ships TypeScript types, offers lazy() wrapper and preloadAll() for server-side resolution. Compatible with 103 Early Hints via getLinkHeaders(). Active development with frequent releases.

npm install vite-preload
INSTALL
IMPORT
SIG · VITE-PRELOAD
V
vite-preload
web-frameworkjavascriptv1.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

preloadPlugin
import preloadPlugin from 'vite-preload/plugin'
import { preloadPlugin } from 'vite-preload/plugin'
Default export from 'vite-preload/plugin' subpath; named import will not work.
createChunkCollector
import { createChunkCollector } from 'vite-preload'
const createChunkCollector = require('vite-preload').createChunkCollector
ESM-only; named import from main path. CJS require may fail in some environments.
ChunkCollectorContext
import { ChunkCollectorContext } from 'vite-preload'
import ChunkCollectorContext from 'vite-preload'
Named export, not default. Wraps server render to collect chunks.
preloadAll
import { preloadAll } from 'vite-preload'
import { preloadAll } from 'vite-preload/plugin'
Client-side/server-side helper from main entry, not from plugin subpath.
lazy
import { lazy } from 'vite-preload'
import { lazy } from 'react'
This is a React.lazy wrapper with preload detection; replaces React.lazy usage.

Shows Vite plugin setup, server-side chunk collector initialization, Early Hints, and link tag injection.

// vite.config.ts import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import preloadPlugin from 'vite-preload/plugin'; export default defineConfig({ plugins: [ preloadPlugin(), react() ] }); // server/entry.server.tsx (simplified) import { ChunkCollectorContext, createChunkCollector, preloadAll } from 'vite-preload'; import React from 'react'; import { renderToPipeableNodeStream } from 'react-dom/server'; // On server startup: await preloadAll(); // In request handler: const collector = createChunkCollector({ manifest: './dist/client/.vite/manifest.json', entry: 'index.html' }); // Early Hints res.writeEarlyHints({ link: collector.getLinkHeaders() }); const { pipe } = renderToPipeableNodeStream( <ChunkCollectorContext.Provider value={collector}> <App /> </ChunkCollectorContext.Provider> ); // After rendering, inject <link> tags into HTML head const linkTags = collector.getLinkTags(); const html = template.replace('</head>', `${linkTags}</head>`); res.write(html);
Debug
Known issues
gotchaPreloading does not work in development mode (vite dev). CSS is injected via inline style tags causing FOUC.
fix
Only rely on preloading for production builds; test CSS appearance separately in dev.
affects: >=0.0.1
gotchaIf modules are not preloaded, check that build.rollupOptions.output.experimentalMinChunkSize is not set, as Rollup may merge chunks and break manifest mapping.
fix
Remove experimentalMinChunkSize or set it to 0.
affects: >=0.0.1
breakingCJS require() may fail in some environments. Package is ESM-only.
fix
Use import syntax or enable ESM in Node.js ("type": "module" in package.json).
affects: >=1.0.0
deprecatedReact 17 is not supported as a peer dependency; only React 18 and 19 are allowed.
fix
Upgrade React to version 18 or later.
affects: >=1.0.0
gotchaThe 'asyncScript' option generates async entry module; React hydration must wait for DOMContentLoaded.
fix
Ensure you do not hydrate or render React before DOMContentLoaded if using asyncScript.
affects: >=1.0.3
breakingThe plugin import path changed: import from 'vite-preload/plugin', not 'vite-preload'.
fix
Use import preloadPlugin from 'vite-preload/plugin'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The 'vite-preload' plugin is not found or not configured correctly.
Importing preloadPlugin from wrong path (e.g., import { preloadPlugin } from 'vite-preload').
fix
Use default import from 'vite-preload/plugin': import preloadPlugin from 'vite-preload/plugin'.
TypeError: Cannot read properties of undefined (reading 'getLinkHeaders')
createChunkCollector returned undefined because manifest path is incorrect or file not found.
fix
Ensure manifest path points to valid file (e.g., './dist/client/.vite/manifest.json') and file exists.
[vite-preload] Chunk not found in manifest: ...
A lazy-loaded module's chunk is missing from the manifest; possibly due to Rollup chunk merging.
fix
Remove build.rollupOptions.output.experimentalMinChunkSize or set to 0.
Error: React.lazy is not supported without the 'lazy' wrapper from vite-preload
Using React.lazy directly instead of the wrapper from 'vite-preload' which collects chunks.
fix
Replace React.lazy with import { lazy } from 'vite-preload'.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
reactrequiredLazy component preloading and context API depend on React
viterequiredRequired as a Vite plugin
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources