typing.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
  2. import type { PluginOption, UserConfig } from 'vite';
  3. import type { PluginOptions } from 'vite-plugin-dts';
  4. import viteTurboConsolePlugin from 'unplugin-turbo-console/vite';
  5. export interface IImportMap {
  6. imports?: Record<string, string>;
  7. scopes?: {
  8. [scope: string]: Record<string, string>;
  9. };
  10. }
  11. /**
  12. * importmap 插件配置
  13. */
  14. interface ImportmapPluginOptions {
  15. /**
  16. * CDN 供应商
  17. * @default jspm.io
  18. */
  19. defaultProvider?: 'esm.sh' | 'jspm.io';
  20. /** importmap 配置 */
  21. importmap?: Array<{ name: string; range?: string }>;
  22. /** 手动配置importmap */
  23. inputMap?: IImportMap;
  24. }
  25. /**
  26. * 用于判断是否需要加载插件
  27. */
  28. interface ConditionPlugin {
  29. // 判断条件
  30. condition?: boolean;
  31. // 插件对象
  32. plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
  33. }
  34. interface CommonPluginOptions {
  35. /** 是否开启devtools */
  36. devtools?: boolean;
  37. /** 环境变量 */
  38. env: Record<string, any>;
  39. /** 是否构建模式 */
  40. isBuild?: boolean;
  41. /** 构建模式 */
  42. mode?: string;
  43. /** 开启依赖分析 */
  44. visualizer?: PluginVisualizerOptions | boolean;
  45. }
  46. interface AppcationPluginOptions extends CommonPluginOptions {
  47. /** 开启 gzip 压缩 */
  48. compress?: boolean;
  49. /** 压缩类型 */
  50. compressTypes?: ('brotli' | 'gzip')[];
  51. /** 在构建的时候抽离配置文件 */
  52. extraAppConfig?: boolean;
  53. /** html 插件配置 */
  54. html?: boolean;
  55. /** 是否开启i18n */
  56. i18n?: boolean;
  57. /** 是否开启 importmap CDN */
  58. importmap?: boolean;
  59. /** importmap 插件配置 */
  60. importmapOptions?: ImportmapPluginOptions;
  61. /** 是否注入app loading */
  62. injectAppLoading?: boolean;
  63. /** mock 插件配置 */
  64. mock?: boolean;
  65. /** turbo-console 插件配置 */
  66. turboConsole?: Parameters<typeof viteTurboConsolePlugin>[0] | boolean;
  67. }
  68. interface LibraryPluginOptions extends CommonPluginOptions {
  69. /** 开启 dts 输出 */
  70. dts?: PluginOptions | boolean;
  71. /** 是否注入lib css */
  72. injectLibCss?: boolean;
  73. }
  74. interface AppcationOptions extends AppcationPluginOptions {}
  75. interface LibraryOptions extends LibraryPluginOptions {}
  76. interface DefineAppcationOptions {
  77. appcation?: AppcationOptions;
  78. vite?: UserConfig;
  79. }
  80. interface DefineLibraryOptions {
  81. library?: LibraryOptions;
  82. vite?: UserConfig;
  83. }
  84. type DefineConfig = {
  85. type?: 'appcation' | 'auto' | 'library';
  86. } & DefineAppcationOptions &
  87. DefineLibraryOptions;
  88. export type {
  89. AppcationPluginOptions,
  90. CommonPluginOptions,
  91. ConditionPlugin,
  92. DefineAppcationOptions,
  93. DefineConfig,
  94. DefineLibraryOptions,
  95. ImportmapPluginOptions,
  96. LibraryPluginOptions,
  97. };