市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.8 KiB

  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. * Set to `false` to disable Options API support and allow related code in
  65. * Vue core to be dropped via dead-code elimination in production builds,
  66. * resulting in smaller bundles.
  67. * - **default:** `true`
  68. */
  69. optionsAPI?: boolean;
  70. /**
  71. * Set to `true` to enable devtools support in production builds.
  72. * Results in slightly larger bundles.
  73. * - **default:** `false`
  74. */
  75. prodDevtools?: boolean;
  76. /**
  77. * Set to `true` to enable detailed information for hydration mismatch
  78. * errors in production builds. Results in slightly larger bundles.
  79. * - **default:** `false`
  80. */
  81. prodHydrationMismatchDetails?: boolean;
  82. /**
  83. * Customize the component ID generation strategy.
  84. * - `'filepath'`: hash the file path (relative to the project root)
  85. * - `'filepath-source'`: hash the file path and the source code
  86. * - `function`: custom function that takes the file path, source code,
  87. * whether in production mode, and the default hash function as arguments
  88. * - **default:** `'filepath'` in development, `'filepath-source'` in production
  89. */
  90. componentIdGenerator?: 'filepath' | 'filepath-source' | ((filepath: string, source: string, isProduction: boolean | undefined, getHash: (text: string) => string) => string);
  91. };
  92. /**
  93. * @deprecated moved to `features.customElement`.
  94. */
  95. customElement?: boolean | string | RegExp | (string | RegExp)[];
  96. }
  97. interface ResolvedOptions extends Omit<Options, 'include' | 'exclude'> {
  98. compiler: typeof _compiler;
  99. root: string;
  100. sourceMap: boolean;
  101. cssDevSourcemap: boolean;
  102. devServer?: ViteDevServer;
  103. devToolsEnabled?: boolean;
  104. }
  105. interface Api {
  106. get options(): ResolvedOptions;
  107. set options(value: ResolvedOptions);
  108. get include(): string | RegExp | (string | RegExp)[] | undefined;
  109. /** include cannot be updated after `options` hook is called */
  110. set include(value: string | RegExp | (string | RegExp)[] | undefined);
  111. get exclude(): string | RegExp | (string | RegExp)[] | undefined;
  112. /** exclude cannot be updated after `options` hook is called */
  113. set exclude(value: string | RegExp | (string | RegExp)[] | undefined);
  114. version: string;
  115. }
  116. declare function vuePlugin(rawOptions?: Options): Plugin<Api>;
  117. declare function vuePluginCjs(this: unknown, options: Options): Plugin<Api>;
  118. //#endregion
  119. export { Api, Options, ResolvedOptions, type VueQuery, vuePlugin as default, vuePluginCjs as "module.exports", parseVueRequest };