logoalt Hacker News

vite_throwawaytoday at 1:58 PM3 repliesview on HN

I have a small React project using vite 7 and have the following in my config so that vite interprets ".js" files as JSX:

    // See https://github.com/vitejs/vite/discussions/14652
    esbuild: {
      loader: "jsx",
      include: /.*\.jsx?$/,
      exclude: [],
    },
    optimizeDeps: {
      esbuildOptions: {
        loader: {
          ".js": "jsx",
        },
      },
    },
Note the comment at the top. I had no idea how to come up with this config by checking the documentation pages of vite and its various related tools. Luckily I found the GitHub issue and someone else had come up with the right incantation.

Now this new vite uses new tools, and their documentation is still lacking. I spent half an hour trying to figure out how vite (and related tools that I had to navigate and try to piece a coherent view of: esbuild, oxc, rolldown, etc.) might be convinced, but gave up and stayed with vite 7.

Someone could respond with a working solution and it would help, sure, but these tools sure as hell have documentation issues.


Replies

spirostoday at 2:25 PM

The solution here is working for me: https://github.com/vitejs/vite/discussions/21505

Though sometimes oxc complains about JSX in JS when running vite, but it still works fine.

show 1 reply
iainmerricktoday at 3:09 PM

Sorry if this comes across as overly facetious — I’m sure you have a reason for doing it that way! — but would it not be easier just to bow to convention and rename your .js files to .jsx?

show 1 reply
ezfetoday at 3:29 PM

I'm curious why you use `.js` files instead of `.jsx`? In my experience, using `jsx` files makes everything work better