/** * @athenna/vite * * (c) João Lenon * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import { Macroable } from '@athenna/common'; import type { FastifyViteOptions, SetAttributes } from '#src/types'; import type { Manifest, ModuleNode, ViteDevServer } from 'vite'; export declare function slash(path: string): string; export declare class Vite extends Macroable { /** * We cache the manifest file content in production * to avoid reading the file multiple times. */ manifestCache?: Manifest; /** * We cache the SSR manifest file content in production * to avoid reading the file multiple times. */ ssrManifestCache?: Manifest; /** * Vite dev server instance. */ devServer?: ViteDevServer; /** * Hold fastify vite options. */ options: FastifyViteOptions; constructor(options: FastifyViteOptions, devServer?: ViteDevServer); /** * Reads the file contents as JSON. */ readFileAsJSON(filePath: string): any; /** * Convert Record of attributes to a valid HTML string. */ makeAttributes(attributes: Record): string; /** * Returns the script needed for the HMR working with Vite. */ getViteHmrScript(attributes?: any): string; /** * If the module is a style module. */ isStyleModule(mod: ModuleNode): boolean; /** * Unwrap attributes from the user defined function or return * the attributes as it is. */ unwrapAttributes(src: string, url: string, attributes?: SetAttributes): Record; /** * Create a style tag for the given path. */ makeStyleTag(src: string, url: string, attributes?: any): string; /** * Create a script tag for the given path */ makeScriptTag(src: string, url: string, attributes?: any): string; /** * Generate a HTML tag for the given asset. */ generateTag(asset: string, attributes?: any): string; /** * Get a chunk from the manifest file for a given file name. */ chunk(manifest: Manifest, entrypoint: string): import("vite").ManifestChunk; /** * Get a list of chunks for a given filename. */ chunksByFile(manifest: Manifest, file: string): import("vite").ManifestChunk[]; /** * Generate preload tag for a given url. */ makePreloadTagForUrl(url: string): string; /** * Collect CSS files from the module graph recursively. */ collectCss(mod: ModuleNode, styleUrls: Set, visitedModules: Set, importer?: ModuleNode): void; /** * Returns path to a given asset file using the manifest file. */ assetPath(asset: string): string; /** * Generate an asset URL for a given asset path. */ generateAssetUrl(path: string): string; /** * Generate style and script tags for the given entrypoints * Also adds the @vite/client script. */ generateEntryPointsTagsForDevMode(entryPoints: string[], attributes?: any): Promise; /** * Generate style and script tags for the given entrypoints * using the manifest file. */ generateEntryPointsTagsWithManifest(entryPoints: string[], attributes?: any): string[]; /** * Generate tags for the entry points. */ generateEntryPointsTags(entryPoints: string[] | string, attributes?: any): Promise; /** * Returns the manifest file contents. * * @throws Will throw an exception when running in dev. */ manifest(): Manifest; /** * Returns the SSR manifest file contents. * * @throws Will throw an exception when running in dev. */ ssrManifest(): Manifest; /** * Returns the script needed for the HMR working with React. */ getReactHmrScript(attributes?: Record): string; /** * Safely load an SSR module by looking to the dev * server or the SSR manifest file. */ ssrLoadModule(modulePath: string): Promise; }