admin-vben5/internal/vite-config/src/typing.ts

344 lines
6.9 KiB
TypeScript
Raw Normal View History

2024-05-19 21:20:42 +08:00
import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
2024-06-16 15:45:15 +08:00
import type { ConfigEnv, PluginOption, UserConfig } from 'vite';
2024-05-19 21:20:42 +08:00
import type { PluginOptions } from 'vite-plugin-dts';
2024-06-16 15:45:15 +08:00
import type { Options as PwaPluginOptions } from 'vite-plugin-pwa';
2024-05-19 21:20:42 +08:00
/**
* 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 {
/** 模块导入映射 */
2024-05-19 21:20:42 +08:00
imports?: Record<string, string>;
/** 作用域特定的导入映射 */
2024-05-19 21:20:42 +08:00
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;
}
2024-05-19 21:20:42 +08:00
/**
*
* @description
*/
interface ArchiverPluginOptions {
/**
*
* @default 'dist'
*/
name?: string;
/**
*
* @default '.'
*/
outputDir?: string;
}
2024-05-19 21:20:42 +08:00
/**
* ImportMap
* @description CDN
2024-05-19 21:20:42 +08:00
*/
interface ImportmapPluginOptions {
/**
* CDN
* @default 'jspm.io'
* @description esm.sh jspm.io CDN
2024-05-19 21:20:42 +08:00
*/
defaultProvider?: 'esm.sh' | 'jspm.io';
/**
* ImportMap
* @description CDN
* @example
* ```typescript
* [
* { name: 'vue' },
* { name: 'pinia', range: '^2.0.0' }
* ]
* ```
*/
2024-05-19 21:20:42 +08:00
importmap?: Array<{ name: string; range?: string }>;
/**
* ImportMap
* @description ImportMap
*/
2024-05-19 21:20:42 +08:00
inputMap?: IImportMap;
}
/**
*
* @description
2024-05-19 21:20:42 +08:00
*/
interface ConditionPlugin {
/**
*
* @description true
*/
2024-05-19 21:20:42 +08:00
condition?: boolean;
/**
*
* @description Promise
*/
2024-05-19 21:20:42 +08:00
plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
}
/**
*
* @description
*/
2024-05-19 21:20:42 +08:00
interface CommonPluginOptions {
/**
*
* @default false
*/
2024-05-19 21:20:42 +08:00
devtools?: boolean;
/**
*
* @description
*/
env?: Record<string, any>;
/**
*
* @default true
*/
2024-06-23 23:18:55 +08:00
injectMetadata?: boolean;
/**
*
* @default false
*/
2024-05-19 21:20:42 +08:00
isBuild?: boolean;
/**
*
* @default 'development'
*/
2024-05-19 21:20:42 +08:00
mode?: string;
/**
*
* @default false
* @description 使 rollup-plugin-visualizer
*/
visualizer?: boolean | PluginVisualizerOptions;
2024-05-19 21:20:42 +08:00
}
/**
*
* @description
*/
interface ApplicationPluginOptions extends CommonPluginOptions {
/**
*
* @default false
* @description zip
*/
archiver?: boolean;
/**
*
* @description
*/
archiverPluginOptions?: ArchiverPluginOptions;
/**
*
* @default false
* @description gzip brotli
*/
2024-05-19 21:20:42 +08:00
compress?: boolean;
/**
*
* @default ['gzip']
* @description
*/
2024-05-19 21:20:42 +08:00
compressTypes?: ('brotli' | 'gzip')[];
/**
*
* @default false
* @description
*/
2024-05-19 21:20:42 +08:00
extraAppConfig?: boolean;
/**
* HTML
* @default true
*/
2024-05-19 21:20:42 +08:00
html?: boolean;
/**
*
* @default false
*/
2024-05-19 21:20:42 +08:00
i18n?: boolean;
/**
* ImportMap CDN
* @default false
*/
2024-05-19 21:20:42 +08:00
importmap?: boolean;
/**
* ImportMap
*/
2024-05-19 21:20:42 +08:00
importmapOptions?: ImportmapPluginOptions;
/**
*
* @default true
*/
2024-05-19 21:20:42 +08:00
injectAppLoading?: boolean;
/**
* SCSS
* @default true
*/
injectGlobalScss?: boolean;
/**
*
* @default true
*/
2024-06-23 19:45:40 +08:00
license?: boolean;
/**
* Nitro Mock
* @default false
*/
nitroMock?: boolean;
/**
* Nitro Mock
*/
nitroMockOptions?: NitroMockPluginOptions;
/**
*
* @default false
*/
print?: boolean;
/**
*
*/
printInfoMap?: PrintPluginOptions['infoMap'];
/**
* PWA
* @default false
*/
2024-06-16 15:45:15 +08:00
pwa?: boolean;
/**
* PWA
*/
2024-06-16 15:45:15 +08:00
pwaOptions?: Partial<PwaPluginOptions>;
/**
* VXE Table
* @default false
*/
vxeTableLazyImport?: boolean;
2024-05-19 21:20:42 +08:00
}
/**
*
* @description
*/
2024-05-19 21:20:42 +08:00
interface LibraryPluginOptions extends CommonPluginOptions {
/**
* DTS
* @default true
* @description TypeScript
*/
dts?: boolean | PluginOptions;
2024-05-19 21:20:42 +08:00
}
/**
*
*/
2024-08-01 00:06:36 +08:00
type ApplicationOptions = ApplicationPluginOptions;
2024-05-19 21:20:42 +08:00
/**
*
*/
2024-08-01 00:06:36 +08:00
type LibraryOptions = LibraryPluginOptions;
2024-05-19 21:20:42 +08:00
/**
*
* @description
*/
type DefineApplicationOptions = (config?: ConfigEnv) => Promise<{
/** 应用插件配置 */
application?: ApplicationOptions;
/** Vite 配置 */
vite?: UserConfig;
}>;
2024-05-19 21:20:42 +08:00
/**
*
* @description
*/
type DefineLibraryOptions = (config?: ConfigEnv) => Promise<{
/** 库插件配置 */
library?: LibraryOptions;
/** Vite 配置 */
vite?: UserConfig;
}>;
2024-05-19 21:20:42 +08:00
/**
*
* @description
*/
type DefineConfig = DefineApplicationOptions | DefineLibraryOptions;
2024-05-19 21:20:42 +08:00
export type {
ApplicationPluginOptions,
ArchiverPluginOptions,
2024-05-19 21:20:42 +08:00
CommonPluginOptions,
ConditionPlugin,
DefineApplicationOptions,
2024-05-19 21:20:42 +08:00
DefineConfig,
DefineLibraryOptions,
IImportMap,
2024-05-19 21:20:42 +08:00
ImportmapPluginOptions,
LibraryPluginOptions,
NitroMockPluginOptions,
PrintPluginOptions,
2024-05-19 21:20:42 +08:00
};