UNPKG

vite-static-assets-plugin

Version:
61 lines (60 loc) 2.08 kB
import type { Plugin } from 'vite'; interface StaticAssetsPluginOptions { /** * Directory to scan for static assets * @default "public" */ directory?: string; /** * Output file for the generated type definitions * @default "src/static-assets.ts" */ outputFile?: string; /** * Array of glob patterns to ignore * @default [".DS_Store"] */ ignore?: string[]; /** * Debounce time in milliseconds for file system events * This is used to avoid too many rebuilds when files are changed rapidly * @default: 200 */ debounce?: number; /** * Enable generation of directory types and helper functions * @default true * NOTE: This MUST be true to generate StaticAssetDirectory and FilesInFolder */ enableDirectoryTypes?: boolean; /** * Maximum directory nesting level for type generation * @default 5 */ maxDirectoryDepth?: number; /** * Whether to allow referencing empty directories in transform hook validation * @default false */ allowEmptyDirectories?: boolean; /** * Whether asset URLs generated by staticAssets() should have a leading slash * @default true * Note: This is separate from Vite's `base` config applied at runtime. */ addLeadingSlash?: boolean; } /** * Asynchronously scan a directory and return all file paths (using Vite's normalizePath). * Based on the user's original function. */ declare function getAllFiles(dir: string, baseDir: string, ignorePatterns?: string[]): Promise<string[]>; /** * Generates the TypeScript code content including FilesInFolder generic. * Based on user's original function structure + generic addition. */ declare function generateTypeScriptCode(files: string[], sourceDirAbsolutePath: string, // For error messages basePath?: string, // From Vite config options?: StaticAssetsPluginOptions): string; export { getAllFiles, generateTypeScriptCode }; export default function staticAssetsPlugin(options?: StaticAssetsPluginOptions): Plugin;