[d565449] | 1 | import { TransformOptions, ParserOptions } from '@babel/core';
|
---|
| 2 | import { PluginOption, ResolvedConfig } from 'vite';
|
---|
| 3 |
|
---|
| 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 | type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
---|
| 26 | /**
|
---|
| 27 | * The object type used by the `options` passed to plugins with
|
---|
| 28 | * an `api.reactBabel` method.
|
---|
| 29 | */
|
---|
| 30 | interface ReactBabelOptions extends BabelOptions {
|
---|
| 31 | plugins: Extract<BabelOptions['plugins'], any[]>;
|
---|
| 32 | presets: Extract<BabelOptions['presets'], any[]>;
|
---|
| 33 | overrides: Extract<BabelOptions['overrides'], any[]>;
|
---|
| 34 | parserOpts: ParserOptions & {
|
---|
| 35 | plugins: Extract<ParserOptions['plugins'], any[]>;
|
---|
| 36 | };
|
---|
| 37 | }
|
---|
| 38 | type ReactBabelHook = (babelConfig: ReactBabelOptions, context: ReactBabelHookContext, config: ResolvedConfig) => void;
|
---|
| 39 | type ReactBabelHookContext = {
|
---|
| 40 | ssr: boolean;
|
---|
| 41 | id: string;
|
---|
| 42 | };
|
---|
| 43 | type ViteReactPluginApi = {
|
---|
| 44 | /**
|
---|
| 45 | * Manipulate the Babel options of `@vitejs/plugin-react`
|
---|
| 46 | */
|
---|
| 47 | reactBabel?: ReactBabelHook;
|
---|
| 48 | };
|
---|
| 49 | declare function viteReact(opts?: Options): PluginOption[];
|
---|
| 50 | declare namespace viteReact {
|
---|
| 51 | var preambleCode: string;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | export { type BabelOptions, type Options, type ReactBabelOptions, type ViteReactPluginApi, viteReact as default };
|
---|