Skip to content

How to have sx with vite? #1657

Answered by estaub
estaub asked this question in Q&A
Discussion options

You must be logged in to vote

I realized overnight that the same problem would probably occur with emotion+vite (without theme-ui), so I searched for that, and found https://dev.to/ajitsinghkamal/using-emotionjs-with-vite-2ndj . A fix for this problem is to add an esbuild section to vite.config.ts, that tells how to deal with jsx:

export default defineConfig({
  plugins: [reactRefresh()],
  esbuild: {
    jsxFactory: 'jsx',
    jsxInject: 'import {jsx} from "theme-ui"',
  }
})

With this approach, there's no need for the jsxImportSource pragma:

/** @jsxImportSource theme-ui */

Note that this is probably also dependent on "jsx": "preserve" in my tsconfig.json.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by estaub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant