import type {Plugin, OutputChunk, OutputAsset, OutputBundle, TransformModuleJSON, } from 'rollup'; import {FilterPattern} from "@rollup/pluginutils"; import type {DefaultTreeAdapterMap} from "parse5"; import {PreRenderedChunk} from "rollup"; export interface RollupHtmlTransformContext { id?: string; // bundle: OutputBundle; // files: Record; } export interface RollupHtmlLoadContext { node: DefaultTreeAdapterMap['element']; sourceId: string; } export interface RollupHtmlResolveContext { node: DefaultTreeAdapterMap['element']; sourceId: string; } export type TransformCallback = (source: string, transformContext: RollupHtmlTransformContext) => string|Promise; export type LoadReference = {get: ()=>string, set: (id: string)=>void}; export type LoadResult = LoadReference|LoadReference[]|undefined|void|false; export type LoadNodeCallback = (loadContext: RollupHtmlLoadContext) => LoadResult|Promise; export type ResolveResult = string|true|undefined|void|false; export type ResolveCallback = (id: string, resolveContext: RollupHtmlResolveContext) => ResolveResult|Promise; export interface RollupHtmlOptions { publicPath?: string; /** * Follows the same logic as rollup's [entryFileNames](https://rollupjs.org/configuration-options/#output-entryfilenames). */ htmlFileNames?: string|((chunkInfo: PreRenderedChunk) => string); /** * Transform a source file passed into this plugin to HTML. For example: a handlebars transform * ``` * transform(source){ * return handlebars.compile(source)({myVar:'example'}) * } * ``` */ transform?: TransformCallback; /** * Detect which references (, ) to resolve from a HTML node. * This rarely needs to be overloaded, but can be used to support non-native attributes used by custom-elements. * * Return false to skip any further processing on this node. Else return the id's the resolve based on this node */ load?: LoadNodeCallback; /** * Callback to filter which references actually need to be resolved. Here you can filter out: * - Links to extensions that don't need to be handled through rollup * - Resources that are external to the app (for example non-relative paths) * - Page navigation within the app * * Return a falsey value to skip this reference. Return true to resolve as is. (or string to transform the id) */ resolve?: ResolveCallback; include?: FilterPattern; exclude?: FilterPattern } /** * A Rollup plugin which creates HTML files to serve Rollup bundles. * @param options - Plugin options. * @returns Plugin instance. */ export default function html(options?: RollupHtmlOptions): Plugin;