Skip to content

fix: do not set jsxImportSource when using babel #156

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

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
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
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function preactPlugin({
babelOptions.parserOpts ||= {} as any;
babelOptions.parserOpts.plugins ||= [];

let useBabel: boolean;
let useBabel = typeof babel !== "undefined";
const shouldTransform = createFilter(
include || [/\.[cm]?[tj]sx?$/],
exclude || [/node_modules/],
Expand Down Expand Up @@ -191,10 +191,12 @@ function preactPlugin({
},
},
// While this config is unconditional, it'll only be used if Babel is not
esbuild: {
jsx: "automatic",
jsxImportSource: jsxImportSource ?? "preact",
},
esbuild: useBabel
? undefined
: {
jsx: "automatic",
jsxImportSource: jsxImportSource ?? "preact",
},
optimizeDeps: {
include: ["preact", "preact/jsx-runtime", "preact/jsx-dev-runtime"],
},
Expand All @@ -204,8 +206,7 @@ function preactPlugin({
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled ?? (!config.isProduction || devtoolsInProd);
useBabel =
!config.isProduction || devToolsEnabled || typeof babel !== "undefined";
useBabel ||= !config.isProduction || !!devToolsEnabled;
},
async transform(code, url) {
// Ignore query parameters, as in Vue SFC virtual modules.
Expand Down