Git Product home page Git Product logo

Comments (7)

seivan avatar seivan commented on June 12, 2024

Notes:

  • TSConfing "jsx": "react" is opt out of automatic runtime.
  • TSConfig defined "jsxImportSource": "react" is default to current settings.
  • Anything else, read pass on as is.

Did a go at it.

const jsxImportSrc = tsBuildConfig.compilerOptions.jsxImportSource
const jsxOption = tsBuildConfig.compilerOptions.jsx === "react"
  ? {}
  : jsxImportSrc === "react"
    ? {}
    : { jsxRuntime: "automatic" as const, jsxImportSrc, }


ReactPlugin({ ...jsxOption, })

Worked perfectly with others, like @emotion/react

    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react",

and

    "jsx": "react-jsx",
    "jsxImportSource": "react",

from vite-plugin-react.

bluwy avatar bluwy commented on June 12, 2024

Does esbuild support jsxImportSource? According to https://esbuild.github.io/content-types/#tsconfig-json only a few fields are supported which Vite passes. Maybe this is related to plugin-react and it's babel transform, but regardless it would be great if you can submit the PR so it's easier to view the proposed changes.

from vite-plugin-react.

seivan avatar seivan commented on June 12, 2024

All the heavy lifting is already done by the React plugin, this is purely a convenience feature. Making sure that we don't repeat configs and keep one single source of truth.

from vite-plugin-react.

alex-kinokon avatar alex-kinokon commented on June 12, 2024

Yes, esbuild does support jsxImportSource.

from vite-plugin-react.

ArnaudBarre avatar ArnaudBarre commented on June 12, 2024

Now that jsx transformation is done by esbuild and that the esbuild plugin correctly read this options, it should be as easy as removing this line https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L152 for TS projects.

This should also enable multiple runtime per app that someone asked in the discussions.

But I don't know how to handle that for JS project (or more complicated, mixed projects)

from vite-plugin-react.

github-actions avatar github-actions commented on June 12, 2024

Hello @seivan. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

from vite-plugin-react.

ArnaudBarre avatar ArnaudBarre commented on June 12, 2024

Hi!
Just tested with the latest version of Vite and the plugin and it it's already working in fact (with one TS config that specify jsxImportSource and no options for the react plugin).
If you have a more complex usecase not supported please share a repro

from vite-plugin-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.