Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to specify plugin-transform-react-jsx throwIfNamespace #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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?$/],
Expand Down Expand Up @@ -196,6 +205,7 @@ function preactPlugin({
? "@babel/plugin-transform-react-jsx"
: "@babel/plugin-transform-react-jsx-development",
{
...config.jsxOpts,
runtime: "automatic",
importSource: jsxImportSource ?? "preact",
},
Expand Down