Skip to content

Commit

Permalink
refactor: 💅 更新类型定义导入,优化类型定义结构;引入Prettify类型工具,美化类型显示
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanisper committed Feb 26, 2025
1 parent dfe2e38 commit 6ee5f59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PluginOption } from 'vite'
import type { IOptions } from './type.d'
import type { IOptions } from './type'
import AsyncComponent from './async-component'
import AsyncImport from './async-import'
import { ParseOptions } from './common/ParseOptions'
Expand All @@ -25,4 +25,4 @@ export default (options: IOptions = {}): PluginOption => {
]
}

export * from './type.d'
export type * from './type'
10 changes: 7 additions & 3 deletions src/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { BuildOptions, IndexHtmlTransformContext, ModuleNode, splitVendorChunk } from 'vite'

export type Prettify<T> = {
[K in keyof T]: T[K]
} & {}

// #region Rollup 相关类型定义获取
type ExtractOutputOptions<T> = T extends (infer U)[] ? U : T extends undefined ? never : T
export type OutputOptions = ExtractOutputOptions<Exclude<BuildOptions['rollupOptions'], undefined>['output']>
Expand Down Expand Up @@ -63,15 +67,15 @@ export interface IOptions {
*
* @description 默认为true,即开启所有功能
*/
enable?: boolean | Partial<Record<Enable, boolean>>
enable?: boolean | Prettify<Partial<Record<Enable, boolean>>>
/**
* dts文件输出配置(可选)
*
* @description 默认为true,即在项目根目录生成类型定义文件
*/
dts?: Partial<Omit<IDtsOptions, 'name' | 'path'> & Record<Exclude<Enable, 'optimization'>, IDtsOptions | boolean>> | boolean
dts?: Prettify<Partial<Omit<IDtsOptions, 'name' | 'path'> & Record<Exclude<Enable, 'optimization'>, IDtsOptions | boolean>>> | boolean
/**
* log 控制,默认不启用,为false
*/
logger?: boolean | Enable[]
logger?: Prettify<boolean | Enable[]>
}
2 changes: 1 addition & 1 deletion src/utils/lex-parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export function parseAsyncImports(source: string) {

export * from './parse_arguments'
export * from './parse_import'
export * from './type.d'
export type * from './type'

0 comments on commit 6ee5f59

Please sign in to comment.