index.d.mts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { Plugin, ViteDevServer } from "vite";
  2. import * as _compiler from "vue/compiler-sfc";
  3. import { SFCScriptCompileOptions, SFCStyleCompileOptions, SFCTemplateCompileOptions } from "vue/compiler-sfc";
  4. //#region src/utils/query.d.ts
  5. interface VueQuery {
  6. vue?: boolean;
  7. src?: string;
  8. type?: 'script' | 'template' | 'style' | 'custom';
  9. index?: number;
  10. lang?: string;
  11. raw?: boolean;
  12. url?: boolean;
  13. scoped?: boolean;
  14. id?: string;
  15. }
  16. declare function parseVueRequest(id: string): {
  17. filename: string;
  18. query: VueQuery;
  19. };
  20. //#endregion
  21. //#region src/index.d.ts
  22. interface Options {
  23. include?: string | RegExp | (string | RegExp)[];
  24. exclude?: string | RegExp | (string | RegExp)[];
  25. /**
  26. * In Vite, this option follows Vite's config.
  27. */
  28. isProduction?: boolean;
  29. script?: Partial<Omit<SFCScriptCompileOptions, 'id' | 'isProd' | 'inlineTemplate' | 'templateOptions' | 'sourceMap' | 'genDefaultAs' | 'customElement' | 'defineModel' | 'propsDestructure'>> & {
  30. /**
  31. * @deprecated defineModel is now a stable feature and always enabled if
  32. * using Vue 3.4 or above.
  33. */
  34. defineModel?: boolean;
  35. /**
  36. * @deprecated moved to `features.propsDestructure`.
  37. */
  38. propsDestructure?: boolean;
  39. };
  40. template?: Partial<Omit<SFCTemplateCompileOptions, 'id' | 'source' | 'ast' | 'filename' | 'scoped' | 'slotted' | 'isProd' | 'inMap' | 'ssr' | 'ssrCssVars' | 'preprocessLang'>>;
  41. style?: Partial<Omit<SFCStyleCompileOptions, 'filename' | 'id' | 'isProd' | 'source' | 'scoped' | 'cssDevSourcemap' | 'postcssOptions' | 'map' | 'postcssPlugins' | 'preprocessCustomRequire' | 'preprocessLang' | 'preprocessOptions'>>;
  42. /**
  43. * Use custom compiler-sfc instance. Can be used to force a specific version.
  44. */
  45. compiler?: typeof _compiler;
  46. /**
  47. * Requires @vitejs/plugin-vue@^5.1.0
  48. */
  49. features?: {
  50. /**
  51. * Enable reactive destructure for `defineProps`.
  52. * - Available in Vue 3.4 and later.
  53. * - **default:** `false` in Vue 3.4 (**experimental**), `true` in Vue 3.5+
  54. */
  55. propsDestructure?: boolean;
  56. /**
  57. * Transform Vue SFCs into custom elements.
  58. * - `true`: all `*.vue` imports are converted into custom elements
  59. * - `string | RegExp`: matched files are converted into custom elements
  60. * - **default:** /\.ce\.vue$/
  61. */
  62. customElement?: boolean | string | RegExp | (string | RegExp)[];
  63. /**
  64. * Force all <script setup> Vue SFC (`.vue`) files to compile in Vapor mode.
  65. * When enabled, this acts as a plugin-level fallback for SFCs without the
  66. * per-file `vapor` marker.
  67. * - Available in Vue 3.6 and later.
  68. * - **default:** `false`
  69. */
  70. vapor?: boolean;
  71. /**
  72. * Set to `false` to disable Options API support and allow related code in
  73. * Vue core to be dropped via dead-code elimination in production builds,
  74. * resulting in smaller bundles.
  75. * - **default:** `true`
  76. */
  77. optionsAPI?: boolean;
  78. /**
  79. * Set to `true` to enable devtools support in production builds.
  80. * Results in slightly larger bundles.
  81. * - **default:** `false`
  82. */
  83. prodDevtools?: boolean;
  84. /**
  85. * Set to `true` to enable detailed information for hydration mismatch
  86. * errors in production builds. Results in slightly larger bundles.
  87. * - **default:** `false`
  88. */
  89. prodHydrationMismatchDetails?: boolean;
  90. /**
  91. * Customize the component ID generation strategy.
  92. * - `'filepath'`: hash the file path (relative to the project root)
  93. * - `'filepath-source'`: hash the file path and the source code
  94. * - `function`: custom function that takes the file path, source code,
  95. * whether in production mode, and the default hash function as arguments
  96. * - **default:** `'filepath'` in development, `'filepath-source'` in production
  97. */
  98. componentIdGenerator?: 'filepath' | 'filepath-source' | ((filepath: string, source: string, isProduction: boolean | undefined, getHash: (text: string) => string) => string);
  99. };
  100. /**
  101. * @deprecated moved to `features.customElement`.
  102. */
  103. customElement?: boolean | string | RegExp | (string | RegExp)[];
  104. }
  105. interface ResolvedOptions extends Omit<Options, 'include' | 'exclude'> {
  106. compiler: typeof _compiler;
  107. root: string;
  108. sourceMap: boolean;
  109. cssDevSourcemap: boolean;
  110. devServer?: ViteDevServer;
  111. devToolsEnabled?: boolean;
  112. }
  113. interface Api {
  114. get options(): ResolvedOptions;
  115. set options(value: ResolvedOptions);
  116. get include(): string | RegExp | (string | RegExp)[] | undefined;
  117. /** include cannot be updated after `options` hook is called */
  118. set include(value: string | RegExp | (string | RegExp)[] | undefined);
  119. get exclude(): string | RegExp | (string | RegExp)[] | undefined;
  120. /** exclude cannot be updated after `options` hook is called */
  121. set exclude(value: string | RegExp | (string | RegExp)[] | undefined);
  122. version: string;
  123. }
  124. declare function vuePlugin(rawOptions?: Options): Plugin<Api>;
  125. declare function vuePluginCjs(this: unknown, options: Options): Plugin<Api>;
  126. //#endregion
  127. export { Api, Options, ResolvedOptions, type VueQuery, vuePlugin as default, vuePluginCjs as "module.exports", parseVueRequest };