diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 09e54e90c..50bf6556c 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -435,8 +435,18 @@ export default function viteReact(opts: Options = {}): PluginOption[] { viteReact.preambleCode = preambleCode -function loadPlugin(path: string): Promise { - return import(path).then((module) => module.default || module) +const loadedPlugin = new Map() +function loadPlugin(path: string): any { + const cached = loadedPlugin.get(path) + if (cached) return cached + + const promise = import(path).then((module) => { + const value = module.default || module + loadedPlugin.set(path, value) + return value + }) + loadedPlugin.set(path, promise) + return promise } function createBabelOptions(rawOptions?: BabelOptions) {