plugin-html/types/index.d.ts

63 lines
2.3 KiB
TypeScript

import type {Plugin, OutputChunk, OutputAsset, OutputBundle, TransformModuleJSON, } from 'rollup';
import {FilterPattern} from "@rollup/pluginutils";
import type {DefaultTreeAdapterMap} from "parse5";
import {PreRenderedChunk} from "rollup";
import type {LoadNodeCallback} from "./load.d.ts";
export type * from "./load.d.ts"
import type {ResolveCallback} from "./resolve.d.ts";
export type * from "./resolve.d.ts"
export interface RollupHtmlTransformContext {
id?: string;
// bundle: OutputBundle;
// files: Record<string, (OutputChunk | OutputAsset)[]>;
}
export type TransformCallback = (source: string, transformContext: RollupHtmlTransformContext) => string|Promise<string>;
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 (<a href="...">, <img src="...">) 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. Use the load function to add any resources from this node, and replace the import with a placeholder so the plugin knows where to inject the end result
*/
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;