Inject React DevTools hook only in dev via Vite plugin
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/logo.png" />
|
<link rel="icon" type="image/svg+xml" href="/logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>RogueHunter</title>
|
<title>RogueHunter</title>
|
||||||
<script src="http://localhost:8097"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -2,10 +2,26 @@ import { defineConfig } from 'vite'
|
|||||||
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
|
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
|
||||||
import babel from '@rolldown/plugin-babel'
|
import babel from '@rolldown/plugin-babel'
|
||||||
|
|
||||||
|
// Inject the React DevTools standalone hook only during `vite` dev (serve),
|
||||||
|
// so it never ships in a production build.
|
||||||
|
const devtools = () => ({
|
||||||
|
name: 'react-devtools-dev-only',
|
||||||
|
apply: 'serve' as const,
|
||||||
|
transformIndexHtml: {
|
||||||
|
order: 'pre' as const,
|
||||||
|
handler: (html: string) =>
|
||||||
|
html.replace(
|
||||||
|
'</head>',
|
||||||
|
' <script src="http://localhost:8097"></script>\n </head>',
|
||||||
|
),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
babel({ presets: [reactCompilerPreset()] })
|
babel({ presets: [reactCompilerPreset()] }),
|
||||||
|
devtools(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user