vont
Version:
A full-stack framework combining Koa and React with file-based routing
146 lines • 3.12 kB
TypeScript
import type { Context, Next } from 'koa';
/**
* 路由处理函数类型
*/
export type RouteHandler = (ctx: Context) => Promise<void>;
/**
* 中间件类型
*/
export type Middleware = (ctx: Context, next: Next) => Promise<void>;
/**
* API 路由配置
*/
export interface RouteConfig {
path: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
handler: RouteHandler;
middleware: Middleware[];
}
/**
* 页面路由配置
*/
export interface PageRouteConfig {
path: string;
component: any;
}
/**
* API 模块导出类型
*/
export interface ApiModule {
get?: RouteHandler;
post?: RouteHandler;
put?: RouteHandler;
delete?: RouteHandler;
patch?: RouteHandler;
options?: RouteHandler;
middleware?: Middleware[];
}
/**
* Vont 框架配置接口
*
* 注意:viteConfig 使用 any 类型以避免 Vite 版本不一致导致的类型冲突
* 这样可以兼容项目中不同版本的 Vite
*/
export interface VontConfig {
root?: string;
port?: number;
host?: string;
apiPrefix?: string;
apiDir?: string;
pagesDir?: string;
outDir?: string;
framework?: 'react' | 'vue';
viteConfig?: any;
server?: {
hmrPort?: number;
middlewares?: Middleware[];
};
build?: {
sourcemap?: boolean;
minify?: boolean;
target?: string;
};
isDev?: boolean;
}
/**
* 开发服务器选项
*/
export interface DevServerOptions extends VontConfig {
isDev: true;
hmrPort?: number;
}
/**
* 构建选项
*/
export interface BuildOptions extends VontConfig {
root: string;
outDir: string;
apiDir?: string;
serverDir?: string;
}
/**
* 配置定义辅助函数
* 用于在 vont.config.ts 中获得类型提示
*/
export declare function defineConfig(config: VontConfig): VontConfig;
/**
* 插件类型擦除辅助函数
* 用于避免不同 Vite 版本之间的类型冲突
*
* @example
* ```ts
* import { defineConfig, vitePlugin } from 'vont';
* import vue from '@vitejs/plugin-vue';
*
* export default defineConfig({
* viteConfig: {
* plugins: [
* vitePlugin(vue()),
* ],
* },
* });
* ```
*/
export declare function vitePlugin(plugin: any): any;
/**
* 插件数组类型擦除辅助函数
* 用于处理返回插件数组的情况
*
* @example
* ```ts
* import { defineConfig, vitePlugins } from 'vont';
* import tailwindcss from '@tailwindcss/vite';
*
* export default defineConfig({
* viteConfig: {
* plugins: vitePlugins([
* tailwindcss(),
* ]),
* },
* });
* ```
*/
export declare function vitePlugins(plugins: any[]): any[];
/**
* Vont 客户端选项
*/
export interface VontClientOptions {
pagesGlob: Record<string, {
default: any;
}>;
notFoundComponent?: any;
}
/**
* 虚拟客户端生成选项
*/
export interface VirtualClientOptions {
stylesGlob?: string;
pagesGlob?: string;
framework?: 'react' | 'vue';
}
/**
* 虚拟服务器生成选项
*/
export interface VirtualServerOptions {
}
//# sourceMappingURL=index.d.ts.map