perf(build): filter SVGR loads before the JavaScript bridge

This commit is contained in:
Tunglies
2026-11-11 06:17:02 +08:00
parent f86db4b344
commit 84783abb73
+10 -1
View File
@@ -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'],