@joker.front/cli
Version:
The Next-Generation Front-End Toolchain: Swift, Efficient, and Adaptive.
54 lines (53 loc) • 2.17 kB
TypeScript
import { RootNode, Node, ElementNode, ElementAttr } from "@joker.front/sfc";
import { Server } from "../server";
import { Plugin } from "../plugin";
import { OutputBundle, OutputChunk } from "rollup";
import { ResolvedConfig } from "../config";
export declare function parserHtml(html: string): RootNode;
export type HtmlTagDescriptor = {
tag: string;
attrs?: Record<string, any>;
children?: string | HtmlTagDescriptor[];
/**
* 注入位置
* head body默认采取后置注入,如果需要前置注入可以使用pre标记
*/
to?: "head" | "body" | "head-pre" | "body-pre";
};
export type IndexHtmlTransformOption = {
path: string;
fileName: string;
config: ResolvedConfig;
chunk?: OutputChunk;
bundle?: OutputBundle;
originalUrl?: string;
server?: Server;
};
/**
* 需要解析URL的节点
*/
export declare const NEAD_TRANSFORM_URL_TAGS: Record<string, string[]>;
export type IndexHtmlTransformResult = string | HtmlTagDescriptor[] | {
content: string;
tags: HtmlTagDescriptor[];
};
export type IndexHtmlTransformHook = (content: string, option: IndexHtmlTransformOption) => IndexHtmlTransformResult | void | Promise<IndexHtmlTransformResult | void>;
export type IndexHtmlTransform = IndexHtmlTransformHook | {
enforce?: Plugin["enforce"];
transform: IndexHtmlTransformHook;
};
export declare function getHtmlTrasnfroms(plugins: Plugin[]): IndexHtmlTransformHook[][];
export declare function transformHtml(content: string, hooks: IndexHtmlTransformHook[], option: IndexHtmlTransformOption): Promise<string>;
export declare function injectToHtmlHead(content: string, tags: HtmlTagDescriptor[], pre?: boolean): string;
/**
* 从根节点中过滤出所有Elemet节点,并通过callBack实现yield
* @param pnode 父节点
* @param callBack 回调
*/
export declare function filterAstElementNode(pnode: Node, callBack: (node: ElementNode) => void): void;
export declare function getScriptInfo(node: ElementNode): {
src?: ElementAttr;
module: boolean;
async: boolean;
};
export declare function htmlEnvHook(content: string, option: IndexHtmlTransformOption): string;