UNPKG

vite-plugin-custom-preload

Version:

A Vite plugin for custom preload/prefetch resource injection into index.html.

37 lines (36 loc) 1.04 kB
import type { Plugin } from 'vite'; import type { OutputChunk, OutputAsset } from 'rollup'; type LinkAttributes = { rel: string; as?: string; href?: string; type?: string; crossorigin?: boolean | 'anonymous' | 'use-credentials'; media?: string; imagesrcset?: string; imagesizes?: string; referrerpolicy?: string; [key: string]: string | boolean | undefined; }; export interface CustomPreloadOptions { /** * 控制每个 chunk 是否插入及插入属性 * 返回 true/false 或属性对象 */ shouldPreload?: (chunk: OutputChunk | OutputAsset) => boolean | LinkAttributes; /** * preload 或 prefetch */ rel?: 'preload' | 'prefetch'; /** * link插入到index.html的位置,默认为head * 可选值:'head' | 'body' */ position?: 'head' | 'body'; /** * 是否在开发环境也启用插件处理 */ applyInDev?: boolean; } export default function customPreloadPlugin(options?: CustomPreloadOptions): Plugin; export {};