brf/client/test/tsx_hook.ts
2025-11-23 21:44:01 +01:00

26 lines
570 B
TypeScript

import esbuild from 'esbuild'
import { type LoadHook } from 'node:module'
export const load: LoadHook = async function (url, context, nextLoad) {
if (url.endsWith('.tsx')) {
const format = 'module'
const { source } = await nextLoad(url, { ...context, format })
const transformedSource = await esbuild.transform(source, {
loader: 'tsx',
jsx: 'transform',
jsxFactory: 'h',
})
return {
format,
shortCirtcuit: true,
shortCirtcuits: true,
source: transformedSource.code,
}
}
return nextLoad(url)
}