|
| 1 | +import type { Plugin } from "vite"; |
| 2 | +import type { CreateFilter, FilterPattern } from "@rollup/pluginutils"; |
| 3 | +import type { ParserOptions } from "@babel/parser"; |
| 4 | +import type { TransformOptions } from "@babel/core"; |
| 5 | +import type { Node } from "estree"; |
| 6 | + |
| 7 | +export type BabelOptions = Omit< |
| 8 | + TransformOptions, |
| 9 | + | "ast" |
| 10 | + | "filename" |
| 11 | + | "root" |
| 12 | + | "sourceFileName" |
| 13 | + | "sourceMaps" |
| 14 | + | "inputSourceMap" |
| 15 | +>; |
| 16 | + |
| 17 | +export interface PreactPluginOptions { |
| 18 | + /** |
| 19 | + * Whether to use Preact devtools |
| 20 | + * @default !isProduction |
| 21 | + */ |
| 22 | + devToolsEnabled?: boolean; |
| 23 | + |
| 24 | + /** |
| 25 | + * Whether to use prefresh HMR |
| 26 | + * @default true |
| 27 | + */ |
| 28 | + prefreshEnabled?: boolean; |
| 29 | + |
| 30 | + /** |
| 31 | + * Whether to alias react, react-dom to preact/compat |
| 32 | + * @default true |
| 33 | + */ |
| 34 | + reactAliasesEnabled?: boolean; |
| 35 | + |
| 36 | + /** |
| 37 | + * Prerender plugin options |
| 38 | + */ |
| 39 | + prerender?: { |
| 40 | + /** |
| 41 | + * Whether to prerender your app on build |
| 42 | + */ |
| 43 | + enabled: boolean; |
| 44 | + /** |
| 45 | + * Absolute path to script containing an exported `prerender()` function |
| 46 | + */ |
| 47 | + prerenderScript?: string; |
| 48 | + /** |
| 49 | + * Query selector for specifying where to insert prerender result in your HTML template |
| 50 | + */ |
| 51 | + renderTarget?: string; |
| 52 | + /** |
| 53 | + * Additional routes that should be prerendered |
| 54 | + */ |
| 55 | + additionalPrerenderRoutes?: string[]; |
| 56 | + /** |
| 57 | + * Vite's preview server won't use our prerendered HTML by default, this middleware correct this |
| 58 | + */ |
| 59 | + previewMiddlewareEnabled?: boolean; |
| 60 | + /** |
| 61 | + * Path to use as a fallback/404 route, i.e., `/404` or `/not-found` |
| 62 | + */ |
| 63 | + previewMiddlewareFallback?: string; |
| 64 | + }; |
| 65 | + |
| 66 | + /** |
| 67 | + * RegExp or glob to match files to be transformed |
| 68 | + */ |
| 69 | + include?: FilterPattern; |
| 70 | + |
| 71 | + /** |
| 72 | + * RegExp or glob to match files to NOT be transformed |
| 73 | + */ |
| 74 | + exclude?: FilterPattern; |
| 75 | + |
| 76 | + /** |
| 77 | + * Babel configuration applied in both dev and prod. |
| 78 | + */ |
| 79 | + babel?: BabelOptions; |
| 80 | + /** |
| 81 | + * Import Source for jsx. Defaults to "preact". |
| 82 | + */ |
| 83 | + jsxImportSource?: string; |
| 84 | +} |
| 85 | + |
| 86 | +export interface PreactBabelOptions extends BabelOptions { |
| 87 | + plugins: Extract<BabelOptions["plugins"], any[]>; |
| 88 | + presets: Extract<BabelOptions["presets"], any[]>; |
| 89 | + overrides: Extract<BabelOptions["overrides"], any[]>; |
| 90 | + parserOpts: ParserOptions & { |
| 91 | + plugins: Extract<ParserOptions["plugins"], any[]>; |
| 92 | + }; |
| 93 | +} |
| 94 | + |
| 95 | +type RollupFilter = ReturnType<CreateFilter>; |
| 96 | + |
| 97 | +export interface PreactDevtoolsPluginOptions { |
| 98 | + devToolsEnabled?: boolean; |
| 99 | + shouldTransform: RollupFilter; |
| 100 | +} |
| 101 | + |
| 102 | +export interface TransformHookNamesPluginOptions { |
| 103 | + devToolsEnabled?: boolean; |
| 104 | + shouldTransform: RollupFilter; |
| 105 | +} |
| 106 | + |
| 107 | +export type NodeWithRange<N extends Node = Node> = N & { |
| 108 | + start: number; |
| 109 | + end: number; |
| 110 | +}; |
| 111 | + |
| 112 | +declare function preactPlugin(options?: PreactPluginOptions): Plugin[]; |
| 113 | + |
| 114 | +export default preactPlugin; |
| 115 | +export { preactPlugin as preact }; |
0 commit comments