Skip to content
Merged
Changes from 2 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
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function preactPlugin({
babelOptions.parserOpts ||= {} as any;
babelOptions.parserOpts.plugins ||= [];

let useBabel: boolean;
const shouldTransform = createFilter(
include || [/\.[tj]sx?$/],
exclude || [/node_modules/],
Expand All @@ -151,6 +152,10 @@ function preactPlugin({
},
},
},
esbuild: {
jsx: "automatic",
jsxImportSource: jsxImportSource ?? "preact",
},
optimizeDeps: {
include: ["preact/jsx-runtime", "preact/jsx-dev-runtime"],
},
Expand All @@ -160,12 +165,15 @@ function preactPlugin({
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled ?? (!config.isProduction || devtoolsInProd);

useBabel =
!config.isProduction || devToolsEnabled || typeof babel !== "undefined";
},
async transform(code, url) {
// Ignore query parameters, as in Vue SFC virtual modules.
const { id } = parseId(url);

if (!shouldTransform(id)) return;
if (!useBabel || !shouldTransform(id)) return;

const parserPlugins = [
...baseParserOptions,
Expand Down