Run a transform
hook before JSX is compiled but after TypeScript syntax is removed
#16630
-
My Can this be done in Vite? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It appears that using // Remove any TypeScript syntax but preserve JSX.
if (id.endsWith('.tsx')) {
const transformed = await vite.transformWithEsbuild(code, id, {
jsx: 'preserve',
loader: 'tsx',
})
return {
code: transformed.code,
map: transformed.map,
meta: { isFoo: true },
}
}
return {
meta: { isFoo: true },
} In the second plugin's transform hook, I call Also important is that the |
Beta Was this translation helpful? Give feedback.
It appears that using
vite.transformWithEsbuild
within my transform hook is the best approach. Since my transform hook produces a sourcemap of its own, I've had to split my plugin into two plugins (each with its own transform hook) so that Vite combines the sourcemap I produce with the onetransformWithEsbuild
produces.In the second plugin's transform hook, I call
this.ge…