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

refactor: Use ESBuild in prod if a user does not require Babel #114

Merged
merged 4 commits into from
Mar 18, 2024
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: {
rschristian marked this conversation as resolved.
Show resolved Hide resolved
jsx: "automatic",
jsxImportSource: jsxImportSource ?? "preact",
rschristian marked this conversation as resolved.
Show resolved Hide resolved
},
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";
rschristian marked this conversation as resolved.
Show resolved Hide resolved
},
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
Loading