diff --git a/README.md b/README.md index c30bfbd..62c90a0 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ export default defineConfig({ | `reactAliasesEnabled` | `boolean` | `true` | Aliases `react`, `react-dom` to `preact/compat` | | `babel` | `object` | | See [Babel configuration](#babel-configuration) | | `prerender` | `object` | | See [Prerendering configuration](#prerendering-configuration) | +| `jsxOpts` | `object` | | See [Additional JSX configuration](#additional-jsx-configuration) | #### Babel configuration @@ -113,6 +114,12 @@ export async function prerender(data) { } ``` +#### Additional JSX configuration + +| Option | Type | Default | Description | +|---|---|---|---| +| `throwIfNamespace` | `boolean` | `false` | Allows specifying throwIfNamespace for `@babel/plugin-transform-react-jsx` and `@babel/plugin-transform-react-jsx-development` | + ## License MIT, see [the license file](./LICENSE). diff --git a/src/index.ts b/src/index.ts index 029cbdb..095999d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,10 @@ export type BabelOptions = Omit< | "inputSourceMap" >; +export type JsxOptions = { + throwIfNamespace?: boolean; +}; + export interface PreactPluginOptions { /** * Inject devtools bridge in production bundle instead of only in development mode. @@ -84,6 +88,10 @@ export interface PreactPluginOptions { * Import Source for jsx. Defaults to "preact". */ jsxImportSource?: string; + /** + * Configuration applied to @babel/plugin-transform-react-jsx. + */ + jsxOpts?: JsxOptions; } export interface PreactBabelOptions extends BabelOptions { @@ -125,6 +133,7 @@ function preactPlugin({ babelOptions.overrides ||= []; babelOptions.parserOpts ||= {} as any; babelOptions.parserOpts.plugins ||= []; + babelOptions.jsxOpts ||= {} as any; const shouldTransform = createFilter( include || [/\.[tj]sx?$/], @@ -196,6 +205,7 @@ function preactPlugin({ ? "@babel/plugin-transform-react-jsx" : "@babel/plugin-transform-react-jsx-development", { + ...config.jsxOpts, runtime: "automatic", importSource: jsxImportSource ?? "preact", },