26 lines
570 B
TypeScript
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)
|
|
}
|