From fd93f65f575d9beee3877ef98c0f57934839473e Mon Sep 17 00:00:00 2001 From: Onur Kerimov Date: Tue, 8 Jul 2025 00:56:15 +0200 Subject: [PATCH] Modify the vite plugin array so that code-inspector-plugin comes before @vitejs/plugin-react or @vitejs/plugin-react-swc --- packages/vite-plugin/src/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/vite-plugin/src/index.ts b/packages/vite-plugin/src/index.ts index 2c77ddaf..44b9c3af 100644 --- a/packages/vite-plugin/src/index.ts +++ b/packages/vite-plugin/src/index.ts @@ -115,5 +115,22 @@ export function ViteCodeInspectorPlugin(options: Options) { `` ); }, + config(config) { + // The "name" field for @vitejs/plugin-react and @vitejs/plugin-react-swc respectively + const reactPluginNames = ['vite:react', 'vite:react-swc']; + + const plugins = config.plugins ?? []; + const selfIndex = plugins.findIndex(p => p?.name === PluginName); + + const reactIndex = plugins.findIndex(p => reactPluginNames.includes(p?.name)); + + if (selfIndex > -1 && reactIndex > -1 && selfIndex > reactIndex) { + // Move self before react + const [selfPlugin] = plugins.splice(selfIndex, 1); + plugins.splice(reactIndex, 0, selfPlugin); + } + + config.plugins = plugins; + }, }; }