UNPKG

vite-preload

Version:

Speed up your Vite application by preloading server rendered lazy modules and stylesheets as early as possible

107 lines (106 loc) 3.12 kB
import { Preload } from './utils'; interface ManifestChunk { src: string; name: string; file: string; isEntry?: boolean; imports?: string[]; dynamicImports?: string[]; css?: string[]; assets?: string[]; } type Manifest = Record<string, ManifestChunk>; export declare class ChunkCollector { manifest: Manifest; entry: string; preloadFonts: boolean; preloadAssets: boolean; nonce: string; asyncScript: boolean; modulesIds: Set<string>; preloads: Map<string, Preload>; constructor(manifest: Manifest, entry: string, preloadFonts?: boolean, preloadAssets?: boolean, nonce?: string, asyncScript?: boolean); /** * Function is called by `ChunkCollectorContext` */ __context_collectModuleId(moduleId: string): void; /** * @deprecated - use getChunks instead */ getSortedModules(): Preload[]; getChunks(): Preload[]; /** * Returns all HTML tags for preload hints and stylesheets. * * See https://vitejs.dev/guide/backend-integration for using your own template */ getTags({ includeEntry, }?: { /** * Will include the entry <script module=""> and entry stylesheets tags. * * If you are using the default Vite settings and having vite transform your index.html * as build time, then the entry tags are already included in the template. */ includeEntry?: boolean; }): string; /** * Returns a `Link` header with all chunks to preload, * including entry chunks. * * @example res.setHeader('link', collector.getLinkHeader()); */ getLinkHeader(): string; /** * Returns an array of `Link` header values * * @example res.append('link', collector.getLinkHeaders()); */ getLinkHeaders(): string[]; } interface CollectorOptions { /** * The Vite manifest or a path to it. * * Set build.manifest: true in your vite config to generate it. * * May be missing in development mode since vite-preload has no effect there * * This is not the ssr-manifest.json. */ manifest?: Manifest | string; /** * The entry module. Defaults to `index.html` */ entry?: string; /** * Preload fonts. * * @default true */ preloadFonts?: boolean; /** * Preload any static imported asset such as image, svgs * * @default false */ preloadAssets?: boolean; /** * Nonce for scripts and stylesheets */ nonce?: string; /** * Set the `async` attribute on the entry <script module=""> tag. * * This requires you to control template generation and add the <script module async> tag to the end of the <body> * or only hydrate React when DOMContentLoaded has fired. * * The polyfill entry script will not be async. */ asyncScript?: boolean; } /** * Create a chunk collector. * This function will throw if not configured correctly */ export declare function createChunkCollector(options: CollectorOptions): ChunkCollector; export {};