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

feat: add rollup:react-compiler task #963

Merged
merged 1 commit into from
Jun 18, 2024
Merged

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Jun 18, 2024

Allows shipping React Compiler output as a separate conditional export condition:

{
  "type": "module",
  "exports": {
    ".": {
      "source": "./src/index.ts",
      "react-compiler": {
        "source": "./src/index.ts",
        "default": "./dist/index.react-compiler.js"
      },
      "require": "./dist/index.cjs",
      "default": "./dist/index.js"
    }
  }
}

There are a few intentional limits:

  • The react-compiler condition only supports ESM output, no CJS.
  • The compile target for react-compiler sets browser targets, not node, as compiled code is supposed to run in the browser (during SSR, or react server component rendering, there is no lifecycles and thus no need to memoize).
  • You have to specify a source condition in the react-compiler condition, even if it's the same as the parent source. I left todos in the code for where we need to implement support for a shorthand: "react-compiler": "./dist/index.react-compiler.js" version.

There's a new root configuration reactCompilerOptions, that applies both if the react-compiler export condition is used, or if the babel.reactCompiler = true option is used.
It's mostly useful to specify a logger.logEvent to see what the compiler is skipping, and for what reason.

@stipsan stipsan requested a review from a team as a code owner June 18, 2024 09:59
@stipsan stipsan enabled auto-merge (squash) June 18, 2024 09:59
Copy link

socket-security bot commented Jun 18, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@sanity/pkg-utils@6.9.4-canary.1 None 0 0 B

🚮 Removed packages: npm/@sanity/pkg-utils@6.9.3

View full report↗︎

@stipsan stipsan force-pushed the react-compiler-condition branch from 17eb219 to efd04e2 Compare June 18, 2024 10:33
@mariuslundgard mariuslundgard self-requested a review June 18, 2024 16:55
Copy link
Member

@mariuslundgard mariuslundgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

@stipsan stipsan merged commit 1002fac into main Jun 18, 2024
9 checks passed
@stipsan stipsan deleted the react-compiler-condition branch June 18, 2024 17:00
@ecospark ecospark bot mentioned this pull request Jun 18, 2024
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

2 participants