vue-vben-admin/internal/vite-config/src/typing.ts

344 lines
6.9 KiB
TypeScript
Raw Permalink Normal View History

2025-05-02 22:08:36 +08:00
import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
import type { ConfigEnv, PluginOption, UserConfig } from 'vite';
import type { PluginOptions } from 'vite-plugin-dts';
import type { Options as PwaPluginOptions } from 'vite-plugin-pwa';
/**
* ImportMap
* @description
* @example
* ```typescript
* {
* imports: {
* 'vue': 'https://unpkg.com/vue@3.2.47/dist/vue.esm-browser.js'
* },
* scopes: {
* 'https://site.com/': {
* 'vue': 'https://unpkg.com/vue@3.2.47/dist/vue.esm-browser.js'
* }
* }
* }
* ```
*/
interface IImportMap {
/** 模块导入映射 */
imports?: Record<string, string>;
/** 作用域特定的导入映射 */
scopes?: {
[scope: string]: Record<string, string>;
};
}
/**
*
* @description
*/
interface PrintPluginOptions {
/**
*
* @description
* @example
* ```typescript
* {
* 'App Version': '1.0.0',
* 'Build Time': '2024-01-01'
* }
* ```
*/
infoMap?: Record<string, string | undefined>;
}
/**
* Nitro Mock
* @description Nitro Mock
*/
interface NitroMockPluginOptions {
/**
* Mock
* @default '@vbenjs/nitro-mock'
*/
mockServerPackage?: string;
/**
* Mock
* @default 3000
*/
port?: number;
/**
* Mock
* @default false
*/
verbose?: boolean;
}
/**
*
* @description
*/
interface ArchiverPluginOptions {
/**
*
* @default 'dist'
*/
name?: string;
/**
*
* @default '.'
*/
outputDir?: string;
}
/**
* ImportMap
* @description CDN
*/
interface ImportmapPluginOptions {
/**
* CDN
* @default 'jspm.io'
* @description esm.sh jspm.io CDN
*/
defaultProvider?: 'esm.sh' | 'jspm.io';
/**
* ImportMap
* @description CDN
* @example
* ```typescript
* [
* { name: 'vue' },
* { name: 'pinia', range: '^2.0.0' }
* ]
* ```
*/
importmap?: Array<{ name: string; range?: string }>;
/**
* ImportMap
* @description ImportMap
*/
inputMap?: IImportMap;
}
/**
*
* @description
*/
interface ConditionPlugin {
/**
*
* @description true
*/
condition?: boolean;
/**
*
* @description Promise
*/
plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
}
/**
*
* @description
*/
interface CommonPluginOptions {
/**
*
* @default false
*/
devtools?: boolean;
/**
*
* @description
*/
env?: Record<string, any>;
/**
*
* @default true
*/
injectMetadata?: boolean;
/**
*
* @default false
*/
isBuild?: boolean;
/**
*
* @default 'development'
*/
mode?: string;
/**
*
* @default false
* @description 使 rollup-plugin-visualizer
*/
visualizer?: boolean | PluginVisualizerOptions;
}
/**
*
* @description
*/
interface ApplicationPluginOptions extends CommonPluginOptions {
/**
*
* @default false
* @description zip
*/
archiver?: boolean;
/**
*
* @description
*/
archiverPluginOptions?: ArchiverPluginOptions;
/**
*
* @default false
* @description gzip brotli
*/
compress?: boolean;
/**
*
* @default ['gzip']
* @description
*/
compressTypes?: ('brotli' | 'gzip')[];
/**
*
* @default false
* @description
*/
extraAppConfig?: boolean;
/**
* HTML
* @default true
*/
html?: boolean;
/**
*
* @default false
*/
i18n?: boolean;
/**
* ImportMap CDN
* @default false
*/
importmap?: boolean;
/**
* ImportMap
*/
importmapOptions?: ImportmapPluginOptions;
/**
*
* @default true
*/
injectAppLoading?: boolean;
/**
* SCSS
* @default true
*/
injectGlobalScss?: boolean;
/**
*
* @default true
*/
license?: boolean;
/**
* Nitro Mock
* @default false
*/
nitroMock?: boolean;
/**
* Nitro Mock
*/
nitroMockOptions?: NitroMockPluginOptions;
/**
*
* @default false
*/
print?: boolean;
/**
*
*/
printInfoMap?: PrintPluginOptions['infoMap'];
/**
* PWA
* @default false
*/
pwa?: boolean;
/**
* PWA
*/
pwaOptions?: Partial<PwaPluginOptions>;
/**
* VXE Table
* @default false
*/
vxeTableLazyImport?: boolean;
}
/**
*
* @description
*/
interface LibraryPluginOptions extends CommonPluginOptions {
/**
* DTS
* @default true
* @description TypeScript
*/
dts?: boolean | PluginOptions;
}
/**
*
*/
type ApplicationOptions = ApplicationPluginOptions;
/**
*
*/
type LibraryOptions = LibraryPluginOptions;
/**
*
* @description
*/
type DefineApplicationOptions = (config?: ConfigEnv) => Promise<{
/** 应用插件配置 */
application?: ApplicationOptions;
/** Vite 配置 */
vite?: UserConfig;
}>;
/**
*
* @description
*/
type DefineLibraryOptions = (config?: ConfigEnv) => Promise<{
/** 库插件配置 */
library?: LibraryOptions;
/** Vite 配置 */
vite?: UserConfig;
}>;
/**
*
* @description
*/
type DefineConfig = DefineApplicationOptions | DefineLibraryOptions;
export type {
ApplicationPluginOptions,
ArchiverPluginOptions,
CommonPluginOptions,
ConditionPlugin,
DefineApplicationOptions,
DefineConfig,
DefineLibraryOptions,
IImportMap,
ImportmapPluginOptions,
LibraryPluginOptions,
NitroMockPluginOptions,
PrintPluginOptions,
};