index.d.cts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { ParserOptions, TransformOptions } from "@babel/core";
  2. import { Plugin, ResolvedConfig } from "vite";
  3. //#region src/index.d.ts
  4. interface Options {
  5. include?: string | RegExp | Array<string | RegExp>;
  6. exclude?: string | RegExp | Array<string | RegExp>;
  7. /**
  8. * Control where the JSX factory is imported from.
  9. * https://esbuild.github.io/api/#jsx-import-source
  10. * @default 'react'
  11. */
  12. jsxImportSource?: string;
  13. /**
  14. * Note: Skipping React import with classic runtime is not supported from v4
  15. * @default "automatic"
  16. */
  17. jsxRuntime?: 'classic' | 'automatic';
  18. /**
  19. * Babel configuration applied in both dev and prod.
  20. */
  21. babel?: BabelOptions | ((id: string, options: {
  22. ssr?: boolean;
  23. }) => BabelOptions);
  24. /**
  25. * React Fast Refresh runtime URL prefix.
  26. * Useful in a module federation context to enable HMR by specifying
  27. * the host application URL in the Vite config of a remote application.
  28. * @example
  29. * reactRefreshHost: 'http://localhost:3000'
  30. */
  31. reactRefreshHost?: string;
  32. /**
  33. * If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
  34. */
  35. disableOxcRecommendation?: boolean;
  36. }
  37. type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
  38. /**
  39. * The object type used by the `options` passed to plugins with
  40. * an `api.reactBabel` method.
  41. */
  42. interface ReactBabelOptions extends BabelOptions {
  43. plugins: Extract<BabelOptions['plugins'], any[]>;
  44. presets: Extract<BabelOptions['presets'], any[]>;
  45. overrides: Extract<BabelOptions['overrides'], any[]>;
  46. parserOpts: ParserOptions & {
  47. plugins: Extract<ParserOptions['plugins'], any[]>;
  48. };
  49. }
  50. type ReactBabelHook = (babelConfig: ReactBabelOptions, context: ReactBabelHookContext, config: ResolvedConfig) => void;
  51. type ReactBabelHookContext = {
  52. ssr: boolean;
  53. id: string;
  54. };
  55. type ViteReactPluginApi = {
  56. /**
  57. * Manipulate the Babel options of `@vitejs/plugin-react`
  58. */
  59. reactBabel?: ReactBabelHook;
  60. };
  61. declare function viteReact(opts?: Options): Plugin[];
  62. declare namespace viteReact {
  63. var preambleCode: string;
  64. }
  65. //#endregion
  66. export { BabelOptions, Options, ReactBabelOptions, ViteReactPluginApi, viteReact as default };