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

fix(esbuild): workaround to for esbuild compile options #784

Merged
merged 1 commit into from Jun 24, 2021

Conversation

dfrkp
Copy link
Contributor

@dfrkp dfrkp commented Jun 22, 2021

Motivation

When using esbuild with preact the jsxFactory and jsxFragment parameter are used to use h() rather than React.createElement(). This change ensures that the parameters are passed to the transform function.

Summary

This workaround checks if jsxFactory or jsxFragment are part of the original build options and if so copies them to to the transform options.

NOTE 1: Usually esbuild would just pick up on tsconfig.json - this workaround won't work there. The pararmeters must be provided explicitly.

NOTE 2: The plugin should probably be rewritten on a more fundamental
level as it interefers heavily with the esbuild build process.

Test plan

Setup an esbuild sample project with preact and linaria, then use this build script and check that there is no "React.createElement" in the bundle:

const { build } = require("esbuild");
const linaria = require("@linaria/esbuild");

const prod = process.env.NODE_ENV === "production";

build({
  entryPoints: ["./src/index.tsx"],
  outdir: "dist",
  jsxFactory: "h",
  jsxFragment: "Fragment",
  minify: true,
  bundle: true,
  plugins: [
    linaria.default({
      sourceMap: prod,
    }),
  ],
}).catch(() => process.exit(1));

When using esbuild with preact the jsxFactory and jsxFragment
parameter are used to use h() rather than React.createElement(). This
change ensures that the parameters are passed to the transform
function.

NOTE 1: Usually esbuild would just pick up on tsconfig.json - this
workaround won't work there. The pararmeters must be provided
explicitly.

NOTE 2: The plugin should probably be rewritten on a more fundamental
level as it interefers heavily with the esbuild build process.
@callstack-bot
Copy link

Hey @dfrkp, thank you for your pull request 🤗.
The coverage report for this branch can be viewed here.

@Anber Anber merged commit ac47f43 into callstack:master Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants