typing.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
  2. import type { ConfigEnv, PluginOption, UserConfig } from 'vite';
  3. import type { PluginOptions } from 'vite-plugin-dts';
  4. import type { Options as PwaPluginOptions } from 'vite-plugin-pwa';
  5. interface IImportMap {
  6. imports?: Record<string, string>;
  7. scopes?: {
  8. [scope: string]: Record<string, string>;
  9. };
  10. }
  11. interface PrintPluginOptions {
  12. /**
  13. * 打印的数据
  14. */
  15. infoMap?: Record<string, string | undefined>;
  16. }
  17. interface NitroMockPluginOptions {
  18. /**
  19. * mock server 包名
  20. */
  21. mockServerPackage?: string;
  22. /**
  23. * mock 服务端口
  24. */
  25. port?: number;
  26. /**
  27. * mock 日志是否打印
  28. */
  29. verbose?: boolean;
  30. }
  31. interface ArchiverPluginOptions {
  32. /**
  33. * 输出文件名
  34. * @default dist
  35. */
  36. name?: string;
  37. /**
  38. * 输出目录
  39. * @default .
  40. */
  41. outputDir?: string;
  42. }
  43. /**
  44. * importmap 插件配置
  45. */
  46. interface ImportmapPluginOptions {
  47. /**
  48. * CDN 供应商
  49. * @default jspm.io
  50. */
  51. defaultProvider?: 'esm.sh' | 'jspm.io';
  52. /** importmap 配置 */
  53. importmap?: Array<{ name: string; range?: string }>;
  54. /** 手动配置importmap */
  55. inputMap?: IImportMap;
  56. }
  57. /**
  58. * 用于判断是否需要加载插件
  59. */
  60. interface ConditionPlugin {
  61. // 判断条件
  62. condition?: boolean;
  63. // 插件对象
  64. plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
  65. }
  66. interface CommonPluginOptions {
  67. /** 是否开启devtools */
  68. devtools?: boolean;
  69. /** 环境变量 */
  70. env?: Record<string, any>;
  71. /** 是否注入metadata */
  72. injectMetadata?: boolean;
  73. /** 是否构建模式 */
  74. isBuild?: boolean;
  75. /** 构建模式 */
  76. mode?: string;
  77. /** 开启依赖分析 */
  78. visualizer?: boolean | PluginVisualizerOptions;
  79. }
  80. interface ApplicationPluginOptions extends CommonPluginOptions {
  81. /** 开启后,会在打包dist同级生成dist.zip */
  82. archiver?: boolean;
  83. /** 压缩归档插件配置 */
  84. archiverPluginOptions?: ArchiverPluginOptions;
  85. /** 开启 gzip|brotli 压缩 */
  86. compress?: boolean;
  87. /** 压缩类型 */
  88. compressTypes?: ('brotli' | 'gzip')[];
  89. /** 在构建的时候抽离配置文件 */
  90. extraAppConfig?: boolean;
  91. /** 是否开启html插件 */
  92. html?: boolean;
  93. /** 是否开启i18n */
  94. i18n?: boolean;
  95. /** 是否开启 importmap CDN */
  96. importmap?: boolean;
  97. /** importmap 插件配置 */
  98. importmapOptions?: ImportmapPluginOptions;
  99. /** 是否注入app loading */
  100. injectAppLoading?: boolean;
  101. /** 是否注入全局scss */
  102. injectGlobalScss?: boolean;
  103. /** 是否注入版权信息 */
  104. license?: boolean;
  105. /** 是否开启nitro mock */
  106. nitroMock?: boolean;
  107. /** nitro mock 插件配置 */
  108. nitroMockOptions?: NitroMockPluginOptions;
  109. /** 开启控制台自定义打印 */
  110. print?: boolean;
  111. /** 打印插件配置 */
  112. printInfoMap?: PrintPluginOptions['infoMap'];
  113. /** 是否开启pwa */
  114. pwa?: boolean;
  115. /** pwa 插件配置 */
  116. pwaOptions?: Partial<PwaPluginOptions>;
  117. /** 是否开启vxe-table懒加载 */
  118. vxeTableLazyImport?: boolean;
  119. }
  120. interface LibraryPluginOptions extends CommonPluginOptions {
  121. /** 开启 dts 输出 */
  122. dts?: boolean | PluginOptions;
  123. }
  124. type ApplicationOptions = ApplicationPluginOptions;
  125. type LibraryOptions = LibraryPluginOptions;
  126. type DefineApplicationOptions = (config?: ConfigEnv) => Promise<{
  127. application?: ApplicationOptions;
  128. vite?: UserConfig;
  129. }>;
  130. type DefineLibraryOptions = (config?: ConfigEnv) => Promise<{
  131. library?: LibraryOptions;
  132. vite?: UserConfig;
  133. }>;
  134. type DefineConfig = DefineApplicationOptions | DefineLibraryOptions;
  135. export type {
  136. ApplicationPluginOptions,
  137. ArchiverPluginOptions,
  138. CommonPluginOptions,
  139. ConditionPlugin,
  140. DefineApplicationOptions,
  141. DefineConfig,
  142. DefineLibraryOptions,
  143. IImportMap,
  144. ImportmapPluginOptions,
  145. LibraryPluginOptions,
  146. NitroMockPluginOptions,
  147. PrintPluginOptions,
  148. };