import type { ConfigEnv, UserConfig as ViteConfig } from 'vite'; import type { UserConfig as CSSOptions } from '@unocss/core'; import type { MonitorOptions } from '@deppon/deppon-monitor-browser'; export interface ErrorMonitorOptions extends MonitorOptions { /** * 上传 sourcemap 的目录 * @default 'dist' */ dir?: string; /** * 默认开发环境不启用,即 `process.env.NODE_ENV` 为 `development` 时 * * 开始 `debug` 模式后,开发环境也会强制开启,仅用于调试时 * @default false */ debug?: boolean; } export interface DepponViteConfig { /** * 入口文件路径 * @default 'src/main.ts' 或 'src/main.js' */ entry?: string; /** * html 模板路径,默认在项目根目录 `index.html` * @default 'index.html' */ htmlTemplatePath?: string; /** * 打包目录名 * @default 'dist' */ buildDir?: string; /** * 公共路径 * @default '/' */ publicPath?: string; /** * 是否开启生产环境 sourcemap * @default false */ sourcemap?: boolean; /** * 开发服务器配置 */ devServer?: { port?: number; host?: string; /** * 自定义域名,用于显示访问地址 * 如果设置了此字段,会在控制台显示 domain URL * @example 'dev.example.com' */ domain?: string; https?: boolean; open?: boolean; openPage?: string; proxy?: Record; allowedHosts?: string[] | boolean; }; /** * 路径别名 */ alias?: { [key: string]: string }; /** * less 变量 */ modifyVars?: { [key: string]: string }; /** * 是否禁用打包文件 size 输出信息 * @default true */ disabledBundleSize?: boolean; /** * 自定义 vite 配置,需返回新的完整配置 */ vite?: (config: ViteConfig) => ViteConfig | Promise; /** * 是否开启错误监控 * @default false */ errorMonitor?: ErrorMonitorOptions; /** * 是否启用 unocss * @default false */ unocss?: CSSOptions | boolean; /** * 允许通过 import.meta.env 访问的环境变量前缀 * @default 'VITE_' */ envPrefix?: string | string[]; } export type DepponViteConfigExport = DepponViteConfig | ((env: ConfigEnv) => DepponViteConfig); // 导出函数和值 export function defineConfig(config: DepponViteConfigExport): DepponViteConfigExport; export { loadEnv } from 'vite'; // 导出类型,确保可以从包中导入 export type { ConfigEnv } from 'vite'; export type { UserConfig as ViteConfig } from 'vite';