diff --git a/src/index.ts b/src/index.ts index 95871cd..c831afb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,7 +198,7 @@ async function transformCommonjs({ } else if (dymc) { requires.push(...dymc.importee.map(impt => impt + ';')) runtimes.push(dymc.runtimeFn) - ms.overwrite(node.callee.start, node.callee.end, dymc.runtimeFn) + ms.overwrite(node.callee.start, node.callee.end, dymc.runtimeName) } } diff --git a/test/fixtures/__snapshots__/dynamic.tsx b/test/fixtures/__snapshots__/dynamic.tsx index 42ce118..ad48827 100644 --- a/test/fixtures/__snapshots__/dynamic.tsx +++ b/test/fixtures/__snapshots__/dynamic.tsx @@ -1,15 +1,5 @@ /* [vite-plugin-commonjs] import-require2import-S */ import * as __dynamic_require2import__0__0 from './module-exports/hello.cjs'; import * as __dynamic_require2import__0__1 from './module-exports/world.cjs'; /* [vite-plugin-commonjs] import-require2import-E */function load(name) { - const mod = function __matchRequireRuntime0__(path) { - switch(path) { - case '@/module-exports/hello': - case '@/module-exports/hello.cjs': - return __dynamic_require2import__0__0; - case '@/module-exports/world': - case '@/module-exports/world.cjs': - return __dynamic_require2import__0__1; - default: throw new Error("Cann't found module: " + path); - } -}(`@/module-exports/${name}`); + const mod = __matchRequireRuntime0__(`@/module-exports/${name}`); console.log(mod); return mod; }