import { HtmlTagDescriptor, Plugin } from 'vite';
interface InjectOptions {
tags?: HtmlTagDescriptor[];
customTags?: HtmlTagDesOptions[];
/** 利用注释来动态替换内容 */
commentsTemplate?: CommentOptions[];
}
interface HtmlTagDesOptions {
/**
* 包含一个或多个要匹配的选择器的 DOM 字符串DOMString。该字符串必须是有效的 CSS 选择器字符 */
selector: string;
/** 插入位置 参考 https://developer.mozilla.org/zh-CN/docs/Web/API/Element/insertAdjacentElement */
position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
tag: string;
attrs?: Record;
}
interface CommentOptions {
commentName: string;
tag: string;
attrs?: Record;
}
interface PageOption {
filename: string;
template: string;
entry?: string;
inject?: InjectOptions;
polyfills?: ReplaceTagOptions | HtmlTagDesOptions;
}
declare type ReplaceTagOptions = {
attrs: Record;
};
declare type polyfillOptions = {
/**
* default: 'defaults'
*/
targets?: string | string[] | {
[key: string]: string;
};
/**
* default: false
*/
ignoreBrowserslistConfig?: boolean;
/**
* default: true
*/
polyfills?: boolean | string[];
additionalLegacyPolyfills?: string[];
/**
* default: false
*/
modernPolyfills?: boolean | string[];
/**
* default: true
*/
renderLegacyChunks?: boolean;
/**
* default: false
*/
externalSystemJS?: boolean;
};
interface UserOptions {
/**
* page entry
*/
entry?: string;
/**
* template path
*/
template?: string;
/**
* @description inject options
*/
inject?: InjectOptions;
/**
* @description 多页配置
*/
pages?: PageOption[];
externals?: Record;
/** autoPolyfill 配置 */
autoPolyfill?: polyfillOptions;
/**
* 是否采用Polyfill CDN,需要单独引入Polyfill CDN
*
* @type {boolean}
* @memberof UserOptions
*/
polyfills?: ReplaceTagOptions | HtmlTagDesOptions;
}
declare function vitePluginHtmlTpl(userOptions?: UserOptions): Plugin[];
export { InjectOptions, vitePluginHtmlTpl };