From 3f0c87924bdb2517bc44ac233f78b51d05b3d9c6 Mon Sep 17 00:00:00 2001 From: Nicolas Civade Date: Thu, 13 Aug 2026 11:27:53 +0200 Subject: [PATCH] Inject React DevTools hook only in dev via Vite plugin --- index.html | 1 - vite.config.ts | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 06f1baa..d80a3ae 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,6 @@ RogueHunter -
diff --git a/vite.config.ts b/vite.config.ts index d1203cd..774c3c3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,10 +2,26 @@ import { defineConfig } from 'vite' import react, { reactCompilerPreset } from '@vitejs/plugin-react' 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( + '', + ' \n ', + ), + }, +}) + // https://vite.dev/config/ export default defineConfig({ plugins: [ react(), - babel({ presets: [reactCompilerPreset()] }) + babel({ presets: [reactCompilerPreset()] }), + devtools(), ], })