2024-05-19 13:20:42 +00:00
|
|
|
import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
|
2024-06-16 07:45:15 +00:00
|
|
|
import type { ConfigEnv, PluginOption, UserConfig } from 'vite';
|
2024-05-19 13:20:42 +00:00
|
|
|
import type { PluginOptions } from 'vite-plugin-dts';
|
2024-06-16 07:45:15 +00:00
|
|
|
import type { Options as PwaPluginOptions } from 'vite-plugin-pwa';
|
2024-05-19 13:20:42 +00:00
|
|
|
|
2024-06-02 15:50:58 +00:00
|
|
|
interface IImportMap {
|
2024-05-19 13:20:42 +00:00
|
|
|
imports?: Record<string, string>;
|
|
|
|
scopes?: {
|
|
|
|
[scope: string]: Record<string, string>;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* importmap 插件配置
|
|
|
|
*/
|
|
|
|
interface ImportmapPluginOptions {
|
|
|
|
/**
|
|
|
|
* CDN 供应商
|
|
|
|
* @default jspm.io
|
|
|
|
*/
|
|
|
|
defaultProvider?: 'esm.sh' | 'jspm.io';
|
|
|
|
/** importmap 配置 */
|
|
|
|
importmap?: Array<{ name: string; range?: string }>;
|
|
|
|
/** 手动配置importmap */
|
|
|
|
inputMap?: IImportMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用于判断是否需要加载插件
|
|
|
|
*/
|
|
|
|
interface ConditionPlugin {
|
|
|
|
// 判断条件
|
|
|
|
condition?: boolean;
|
|
|
|
// 插件对象
|
|
|
|
plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CommonPluginOptions {
|
|
|
|
/** 是否开启devtools */
|
|
|
|
devtools?: boolean;
|
2024-05-25 14:43:22 +00:00
|
|
|
/** 环境变量 */
|
2024-06-02 15:50:58 +00:00
|
|
|
env?: Record<string, any>;
|
2024-07-09 15:43:08 +00:00
|
|
|
/** 是否注入metadata */
|
2024-06-23 15:18:55 +00:00
|
|
|
injectMetadata?: boolean;
|
2024-05-19 13:20:42 +00:00
|
|
|
/** 是否构建模式 */
|
|
|
|
isBuild?: boolean;
|
|
|
|
/** 构建模式 */
|
|
|
|
mode?: string;
|
|
|
|
/** 开启依赖分析 */
|
|
|
|
visualizer?: PluginVisualizerOptions | boolean;
|
|
|
|
}
|
|
|
|
|
2024-06-02 15:50:58 +00:00
|
|
|
interface ApplicationPluginOptions extends CommonPluginOptions {
|
2024-05-19 13:20:42 +00:00
|
|
|
/** 开启 gzip 压缩 */
|
|
|
|
compress?: boolean;
|
|
|
|
/** 压缩类型 */
|
|
|
|
compressTypes?: ('brotli' | 'gzip')[];
|
|
|
|
/** 在构建的时候抽离配置文件 */
|
|
|
|
extraAppConfig?: boolean;
|
|
|
|
/** html 插件配置 */
|
|
|
|
html?: boolean;
|
|
|
|
/** 是否开启i18n */
|
|
|
|
i18n?: boolean;
|
|
|
|
/** 是否开启 importmap CDN */
|
|
|
|
importmap?: boolean;
|
|
|
|
/** importmap 插件配置 */
|
|
|
|
importmapOptions?: ImportmapPluginOptions;
|
|
|
|
/** 是否注入app loading */
|
|
|
|
injectAppLoading?: boolean;
|
2024-07-17 14:30:18 +00:00
|
|
|
/** 是否注入全局scss */
|
|
|
|
injectGlobalScss?: boolean;
|
2024-06-23 11:45:40 +00:00
|
|
|
/** 是否注入版权信息 */
|
|
|
|
license?: boolean;
|
2024-06-16 07:45:15 +00:00
|
|
|
/** 是否开启pwa */
|
|
|
|
pwa?: boolean;
|
|
|
|
/** pwa 插件配置 */
|
|
|
|
pwaOptions?: Partial<PwaPluginOptions>;
|
2024-05-19 13:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface LibraryPluginOptions extends CommonPluginOptions {
|
|
|
|
/** 开启 dts 输出 */
|
|
|
|
dts?: PluginOptions | boolean;
|
|
|
|
|
|
|
|
/** 是否注入lib css */
|
|
|
|
injectLibCss?: boolean;
|
|
|
|
}
|
|
|
|
|
2024-06-02 15:50:58 +00:00
|
|
|
interface ApplicationOptions extends ApplicationPluginOptions {}
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
interface LibraryOptions extends LibraryPluginOptions {}
|
|
|
|
|
2024-07-13 13:00:31 +00:00
|
|
|
type DefineApplicationOptions = (config?: ConfigEnv) => Promise<{
|
|
|
|
application?: ApplicationOptions;
|
|
|
|
vite?: UserConfig;
|
|
|
|
}>;
|
2024-05-19 13:20:42 +00:00
|
|
|
|
2024-07-13 13:00:31 +00:00
|
|
|
type DefineLibraryOptions = (config?: ConfigEnv) => Promise<{
|
|
|
|
library?: LibraryOptions;
|
|
|
|
vite?: UserConfig;
|
|
|
|
}>;
|
2024-05-19 13:20:42 +00:00
|
|
|
|
2024-07-13 13:00:31 +00:00
|
|
|
type DefineConfig = DefineApplicationOptions | DefineLibraryOptions;
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
export type {
|
2024-06-02 15:50:58 +00:00
|
|
|
ApplicationPluginOptions,
|
2024-05-19 13:20:42 +00:00
|
|
|
CommonPluginOptions,
|
|
|
|
ConditionPlugin,
|
2024-06-02 15:50:58 +00:00
|
|
|
DefineApplicationOptions,
|
2024-05-19 13:20:42 +00:00
|
|
|
DefineConfig,
|
|
|
|
DefineLibraryOptions,
|
2024-06-02 15:50:58 +00:00
|
|
|
IImportMap,
|
2024-05-19 13:20:42 +00:00
|
|
|
ImportmapPluginOptions,
|
|
|
|
LibraryPluginOptions,
|
|
|
|
};
|