facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.74k stars 26.86k forks source link

tsconf and "jsx": "react-jsxdev" #10025

Open stevenroussey-privicy opened 4 years ago

stevenroussey-privicy commented 4 years ago

Is your proposal related to a problem?

Some options for Typescript you want for production and some for development. The one that will need support soon is "jsx": "react-jsxdev" compiler option for React 17. You want "react-jsx" for production though.

Describe the solution you'd like

One solution is to look for tsconfig.dev.json and use that in development if it exists.

Second solution is to set these values directly and ignore whatever jsx directive is in tsconf.json

Additional context

Typescript 4.1 RC announcement

karlhorky commented 3 years ago

Just found this one now too, due to the final version of TypeScript 4.1 being released: https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/

My question would be: what are the exact functional differences between react-jsxdev and react-jsx? Maybe cc @gaearon ?

Edit: Oh, reading through the RFC, it looks like the DEV mode passes some additional information seemingly for the reason "That way we can easily error if the transform doesn't match.":

I tried reading through Introducing the New JSX Transform on the React blog and similar resources, but was unable to quickly find an answer to this.

srigi commented 3 years ago

I found that with Webpack, you can set this dynamically in webpack.config.js using ts-loader. Just ommit jsx in tsconfig.json and...

  {
    test: /\.tsx?$/,
    exclude: 'node_modules',
    use: {
      loader: 'ts-loader',
      options: {
        compilerOptions: {
          jsx:
            process.env.NODE_ENV === 'development'
              ? 'react-jsxdev'
              : 'react-jsx',
        },
      },
    },
  },