mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
chore(dev): add React profiling and focused A/B workflows
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import path from 'node:path'
|
||||
|
||||
import { normalizePath, type Plugin } from 'vite'
|
||||
|
||||
export function reactDiagnostics(mode: string | undefined): Plugin[] {
|
||||
if (!mode) return []
|
||||
return [
|
||||
{
|
||||
name: 'react-diagnostics',
|
||||
enforce: 'pre',
|
||||
apply: 'serve',
|
||||
config() {
|
||||
if (mode !== 'profiler')
|
||||
throw new Error(`Unknown CVR_REACT_DIAGNOSTICS mode: ${mode}`)
|
||||
},
|
||||
transform(code, id) {
|
||||
if (id !== normalizePath(path.resolve('src/main.tsx'))) return
|
||||
const open = '<React.StrictMode>'
|
||||
const close = '</React.StrictMode>'
|
||||
if (!code.includes(open) || !code.includes(close)) {
|
||||
throw new Error('React profiling entry no longer matches main.tsx')
|
||||
}
|
||||
return {
|
||||
code: `import { Profiler } from 'react'\nimport { recordRender } from '../scripts/react/profiler'\n${code}`
|
||||
.replace(open, `<Profiler id="app" onRender={recordRender}>${open}`)
|
||||
.replace(close, `${close}</Profiler>`),
|
||||
map: null,
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user