-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tsx support #18
Comments
I've got a working setup for this, but it has a few issues before it would be PR ready. You can see the changes at https://github.com/predakanga/viteburner and https://github.com/predakanga/viteburner-template With those minor changes, .jsx and .tsx files work perfectly, you can The main problems are:
|
@predakanga Thanks for your information about how to implement jsx/tsx support! After digging into this issue I come up with the 1.0 milestone addressing some blockers of this issue:
There are other important infrastructure improves, but they are not related to this issue much.
Why do we need this js? I've tested locally with your changes to viteburner. It compiles tsx, although the extension name is incorrect. Does the compiled code missed something in runtime?
We use |
It's loaded by vite-plugin-react when the plugin is instantiated (see here). It doesn't actually do anything in viteburner's usage, but I can't find a way to stop it loading the file.
I didn't realise the extension name is incorrect, what should it be?
The vite/plugin-react uses babel to do the JSX transformation, which is why it needs babel at all. I agree it should only be needed as a devDependency, but if you don't have it installed in the template you get the following error: I think it can be fixed in the viteburner build step, that throws a warning about the same file. |
@predakanga It generates |
After some more experimenting, I've found that we can just use I'm certain there's no way around the I've also found another problem with my approach: Because I'm sure that wouldn't be popular, so it may be a good idea to wait until after #21 to implement this. |
I figured out an approach to support JSX/TSX without any changes to viteburner - only the template. This approach doesn't require any RAM as it doesn't import React for you. Instead it re-exports all of React from a file The only other changes that need to be made would be to add All of this can be done solely through the template! src/vendored/react.ts/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
export default React;
// @ts-ignore
export type * from 'react';
// @ts-ignore
export const {
Children,
Fragment,
Component,
Profiler,
PureComponent,
cloneElement,
createContext,
createElement,
createFactory,
createRef,
forwardRef,
isValidElement,
lazy,
memo,
useCallback,
useContext,
useDebugValue,
useEffect,
useImperativeHandle,
useLayoutEffect,
useMemo,
useReducer,
useRef,
useState,
version,
Suspense,
StrictMode,
// @ts-ignore
} = React; tsconfig.json "compilerOptions":{
+ "jsx": "react",
},
"include":[
- "src/**/*.ts",
+ "src/**/*",
] vite.config.ts resolve:{
alias: {
+ react: resolve(__dirname, 'src', 'vendored', 'react.js'),
}
},
viteburner: {
watch: [
+ {
+ pattern: 'src/**/*.tsx',
+ transform: true,
+ location: (file) => ({ filename: file.replace(/[jt]sx?$/, 'js').replace(/^src/, '') }),
+ },
]
},
+esbuild: {
+ jsx: 'transform',
+} |
Currently
viteburner
doesn't have tsx support out-of-box. We need extra config for vite and the template to let it pass the vite pipeline.The text was updated successfully, but these errors were encountered: