UNPKG

alias-to-config-plugin

Version:

Automatically generate jsconfig.json/tsconfig.json path mappings from Webpack/Vite alias configurations

94 lines 2.35 kB
/** * 配置生成器选项接口 * 用于配置别名到 jsconfig.json 的转换行为 */ export interface ConfigGeneratorOptions { /** * 是否启用插件 * @default true */ enable?: boolean; /** * jsconfig.json文件路径 * @default path.resolve(process.cwd(), "jsconfig.json") | path.resolve(process.cwd(), "tsconfig.json") * @example "./jsconfig.json" */ configPath?: string; /** * 自定义baseUrl,相对于项目根目录 * @default "." * @example "src" */ baseUrl?: string; /** * 排除的别名数组(不需要同步到jsconfig的别名) * @default [] * @example ["@types", "@test"] */ excludeAlias?: string[]; /** * 排除别名的正则表达式 * @default null * @example /^@test/ */ excludeAliasReg?: RegExp | null; /** * 排除路径的正则表达式 * @default null * @example /^@test/ */ excludeAliasPathReg?: RegExp | null; } export interface WebpackAlias { [key: string]: string | string[]; } export interface ViteAlias { [key: string]: string; } /** * Vite别名项(数组形式) * - find 可以为字符串或正则(正则将被跳过,因为 jsconfig/tsconfig paths 不支持) * - replacement 为字符串路径 */ export interface ViteAliasItem { find: string | RegExp; replacement: string; } export type ViteAliasArray = ViteAliasItem[]; /** * 统一的别名入参类型:兼容 Webpack 对象、Vite 对象、Vite 数组三种形式 */ export type AliasInput = WebpackAlias | ViteAlias | ViteAliasArray; export interface JSConfigPaths { [key: string]: string[]; } export interface JSConfig { compilerOptions?: { baseUrl?: string; paths?: JSConfigPaths; [key: string]: any; }; [key: string]: any; } export interface WebpackCompiler { hooks: { afterEnvironment: { tap: (name: string, callback: () => void) => void; }; }; options: { resolve: { alias: WebpackAlias; }; }; } export interface ViteConfig { resolve: { alias: ViteAlias | ViteAliasArray; }; } export interface VitePlugin { name: string; configResolved: (config: ViteConfig) => void; } //# sourceMappingURL=types.d.ts.map