chore: shim react/jsx-runtime to compile JSX modules
This commit is contained in:
parent
ce07a1d6bf
commit
ddb603211b
5 changed files with 24 additions and 2 deletions
|
|
@ -8,6 +8,7 @@
|
|||
"moduleResolution": "bundler",
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
// Type checking
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { transform } from '@swc/core'
|
|||
import { $, main } from 'bun'
|
||||
import chalk from 'chalk'
|
||||
import { type OutputChunk, type RolldownPlugin, rolldown } from 'rolldown'
|
||||
import { aliasPlugin } from 'rolldown/experimental'
|
||||
|
||||
import pkg from '../package.json'
|
||||
|
||||
|
|
@ -33,6 +34,14 @@ export default async function build(dev = false, log = true) {
|
|||
},
|
||||
plugins: [
|
||||
swcPlugin(),
|
||||
aliasPlugin({
|
||||
entries: [
|
||||
{
|
||||
find: 'react/jsx-runtime',
|
||||
replacement: './shims/react~jsx-runtime.ts',
|
||||
},
|
||||
],
|
||||
}),
|
||||
hermesCPlugin({
|
||||
flags: [
|
||||
dev ? '-Og' : '-O',
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ console.info(chalk.redBright(`\nRevenge ${chalk.white(`v${pkg.version}`)}\n`))
|
|||
|
||||
const cwdify = (path: string) => join(process.cwd(), path)
|
||||
const Sources = ['src', 'lib', 'plugins'].map(cwdify)
|
||||
const ExitTriggers = ['scripts', 'package.json', 'bun.lock'].map(cwdify)
|
||||
const ExitTriggers = ['scripts', 'shims', 'package.json', 'bun.lock'].map(cwdify)
|
||||
|
||||
const debouncedBuildDev = debounce(() => ((needRebuild = false), build(true).catch(console.error)), 250)
|
||||
|
||||
|
|
|
|||
12
shims/react~jsx-runtime.ts
Normal file
12
shims/react~jsx-runtime.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { ReactJsxRuntime } from '@revenge-mod/react'
|
||||
import { getProxyTarget, isProxy } from '@revenge-mod/utils/proxy'
|
||||
import type { ElementType } from 'react'
|
||||
|
||||
const { jsx: _jsx, jsxs: _jsxs, Fragment } = ReactJsxRuntime
|
||||
|
||||
const jsx = ((type, ...args) =>
|
||||
_jsx(isProxy(type as object) ? (getProxyTarget(type as object) as ElementType) : type, ...args)) as typeof _jsx
|
||||
const jsxs = ((type, ...args) =>
|
||||
_jsxs(isProxy(type as object) ? (getProxyTarget(type as object) as ElementType) : type, ...args)) as typeof _jsxs
|
||||
|
||||
export { jsx, jsxs, Fragment }
|
||||
|
|
@ -6,5 +6,5 @@
|
|||
"~plugins/*": ["./plugins/*"]
|
||||
}
|
||||
},
|
||||
"include": ["lib", "plugins", "src"]
|
||||
"include": ["lib", "plugins", "src", "shims"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue