Replies: 2 comments
-
|
Related discussion: vitejs#21505 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I found a solution! import { defineConfig, loadEnv, transformWithOxc } from "vite";
import react from "@vitejs/plugin-react";
const transformJsxInJs = () => ({
name: "transform-jsx-in-js",
enforce: "pre",
async transform(code, id) {
if (!id.match(/.*\.js$/)) {
return null;
}
return await transformWithOxc(code, id, {
lang: "jsx",
});
},
});
export default defineConfig(() => {
return {
resolve: {
tsconfigPaths: true,
},
plugins: [
react(),
transformJsxInJs()
],
};
});This hack/plugin might break other stuff down the line (HMR, tree shaking, bundling, who knows), but it's at least able to get me to start experimenting with Vite before converting our large codebase to actual .jsx files. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Based on this StackOverflow answer (that's based off of this Vite discussion comment), I've been using what's in the answer until now to get plain .js files containing JSX to work. This is for an old project that started off from CRA where at the time it was considered best practice to not name your JS files containing as JSX as
.jsx, but rather keep them as.js, the logic being that there are several layers of transpilation happening anyway (minifying, babel plugins, typescript etc.) so you shouldn't try to express all the layers in the extension.Anyway, so now with rolldown-vite since it's not using ESBuild anymore, I'm assuming this part of the vite config won't work anymore:
So would anyone please help me find the equivalent for
rolldown-vite?Beta Was this translation helpful? Give feedback.
All reactions