UNPKG

2.33 kBTypeScriptView Raw
1import { TransformOptions, ParserOptions } from '@babel/core';
2import { ResolvedConfig, PluginOption } from 'vite';
3
4interface Options {
5 include?: string | RegExp | Array<string | RegExp>;
6 exclude?: string | RegExp | Array<string | RegExp>;
7 /**
8 * Enable `react-refresh` integration. Vite disables this in prod env or build mode.
9 * @default true
10 */
11 fastRefresh?: boolean;
12 /**
13 * Set this to `"automatic"` to use [vite-react-jsx](https://github.com/alloc/vite-react-jsx).
14 * @default "automatic"
15 */
16 jsxRuntime?: 'classic' | 'automatic';
17 /**
18 * Control where the JSX factory is imported from.
19 * This option is ignored when `jsxRuntime` is not `"automatic"`.
20 * @default "react"
21 */
22 jsxImportSource?: string;
23 /**
24 * Set this to `true` to annotate the JSX factory with `\/* @__PURE__ *\/`.
25 * This option is ignored when `jsxRuntime` is not `"automatic"`.
26 * @default true
27 */
28 jsxPure?: boolean;
29 /**
30 * Babel configuration applied in both dev and prod.
31 */
32 babel?: BabelOptions | ((id: string, options: {
33 ssr?: boolean;
34 }) => BabelOptions);
35}
36type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
37/**
38 * The object type used by the `options` passed to plugins with
39 * an `api.reactBabel` method.
40 */
41interface ReactBabelOptions extends BabelOptions {
42 plugins: Extract<BabelOptions['plugins'], any[]>;
43 presets: Extract<BabelOptions['presets'], any[]>;
44 overrides: Extract<BabelOptions['overrides'], any[]>;
45 parserOpts: ParserOptions & {
46 plugins: Extract<ParserOptions['plugins'], any[]>;
47 };
48}
49type ReactBabelHook = (babelConfig: ReactBabelOptions, context: ReactBabelHookContext, config: ResolvedConfig) => void;
50type ReactBabelHookContext = {
51 ssr: boolean;
52 id: string;
53};
54declare module 'vite' {
55 interface Plugin {
56 api?: {
57 /**
58 * Manipulate the Babel options of `@vitejs/plugin-react`
59 */
60 reactBabel?: ReactBabelHook;
61 };
62 }
63}
64declare function viteReact(opts?: Options): PluginOption[];
65declare namespace viteReact {
66 var preambleCode: string;
67}
68
69export { BabelOptions, Options, ReactBabelOptions, viteReact as default };