1
0

typing.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /**
  32. * importmap 插件配置
  33. */
  34. interface ImportmapPluginOptions {
  35. /**
  36. * CDN 供应商
  37. * @default jspm.io
  38. */
  39. defaultProvider?: 'esm.sh' | 'jspm.io';
  40. /** importmap 配置 */
  41. importmap?: Array<{ name: string; range?: string }>;
  42. /** 手动配置importmap */
  43. inputMap?: IImportMap;
  44. }
  45. /**
  46. * 用于判断是否需要加载插件
  47. */
  48. interface ConditionPlugin {
  49. // 判断条件
  50. condition?: boolean;
  51. // 插件对象
  52. plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
  53. }
  54. interface CommonPluginOptions {
  55. /** 是否开启devtools */
  56. devtools?: boolean;
  57. /** 环境变量 */
  58. env?: Record<string, any>;
  59. /** 是否注入metadata */
  60. injectMetadata?: boolean;
  61. /** 是否构建模式 */
  62. isBuild?: boolean;
  63. /** 构建模式 */
  64. mode?: string;
  65. /** 开启依赖分析 */
  66. visualizer?: boolean | PluginVisualizerOptions;
  67. }
  68. interface ApplicationPluginOptions extends CommonPluginOptions {
  69. /** 开启 gzip|brotli 压缩 */
  70. compress?: boolean;
  71. /** 压缩类型 */
  72. compressTypes?: ('brotli' | 'gzip')[];
  73. /** 在构建的时候抽离配置文件 */
  74. extraAppConfig?: boolean;
  75. /** 是否开启html插件 */
  76. html?: boolean;
  77. /** 是否开启i18n */
  78. i18n?: boolean;
  79. /** 是否开启 importmap CDN */
  80. importmap?: boolean;
  81. /** importmap 插件配置 */
  82. importmapOptions?: ImportmapPluginOptions;
  83. /** 是否注入app loading */
  84. injectAppLoading?: boolean;
  85. /** 是否注入全局scss */
  86. injectGlobalScss?: boolean;
  87. /** 是否注入版权信息 */
  88. license?: boolean;
  89. /** 是否开启nitro mock */
  90. nitroMock?: boolean;
  91. /** nitro mock 插件配置 */
  92. nitroMockOptions?: NitroMockPluginOptions;
  93. /** 开启控制台自定义打印 */
  94. print?: boolean;
  95. /** 打印插件配置 */
  96. printInfoMap?: PrintPluginOptions['infoMap'];
  97. /** 是否开启pwa */
  98. pwa?: boolean;
  99. /** pwa 插件配置 */
  100. pwaOptions?: Partial<PwaPluginOptions>;
  101. }
  102. interface LibraryPluginOptions extends CommonPluginOptions {
  103. /** 开启 dts 输出 */
  104. dts?: boolean | PluginOptions;
  105. /** 是否注入lib css */
  106. injectLibCss?: boolean;
  107. }
  108. type ApplicationOptions = ApplicationPluginOptions;
  109. type LibraryOptions = LibraryPluginOptions;
  110. type DefineApplicationOptions = (config?: ConfigEnv) => Promise<{
  111. application?: ApplicationOptions;
  112. vite?: UserConfig;
  113. }>;
  114. type DefineLibraryOptions = (config?: ConfigEnv) => Promise<{
  115. library?: LibraryOptions;
  116. vite?: UserConfig;
  117. }>;
  118. type DefineConfig = DefineApplicationOptions | DefineLibraryOptions;
  119. export type {
  120. ApplicationPluginOptions,
  121. CommonPluginOptions,
  122. ConditionPlugin,
  123. DefineApplicationOptions,
  124. DefineConfig,
  125. DefineLibraryOptions,
  126. IImportMap,
  127. ImportmapPluginOptions,
  128. LibraryPluginOptions,
  129. NitroMockPluginOptions,
  130. PrintPluginOptions,
  131. };