From 84783abb7339f5b68c2eba9517996a094fd5bab0 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Wed, 11 Nov 2026 06:17:02 +0800 Subject: [PATCH] perf(build): filter SVGR loads before the JavaScript bridge --- vite.config.mts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vite.config.mts b/vite.config.mts index f8c9ee1c0..85a9bbfc1 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -5,11 +5,20 @@ import react from '@vitejs/plugin-react' import { defineConfig } from 'vite' import svgr from 'vite-plugin-svgr' +const svgPlugin = svgr() +const svgLoad = svgPlugin.load +if (!svgLoad) throw new Error('vite-plugin-svgr must provide a load hook') +// SVGR's internal include filter still crosses the JS bridge for every module. +svgPlugin.load = { + filter: { id: /\.svg\?react$/ }, + handler: typeof svgLoad === 'function' ? svgLoad : svgLoad.handler, +} + export default defineConfig({ root: 'src', server: { port: 3000 }, plugins: [ - svgr(), + svgPlugin, react(), legacy({ modernTargets: ['edge>=109', 'safari>=14'],