diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3675c..92a5b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.8.0 (2023-06-24) + +- bf2f306 fix: dynamic-require typo #28, closes [#28](https://github.com/vite-plugin/vite-plugin-commonjs/issues/28) +- 66ce5dd feat: support build + ## 0.7.1 (2023-05-14) - ddfbfeb fix: bump vite-plugin-dynamic-import to 1.4.0 for `pnpm` diff --git a/package.json b/package.json index 9b95a20..734a491 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-commonjs", - "version": "0.7.1", + "version": "0.8.0", "description": "A pure JavaScript implementation of CommonJs", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 4bb2a97..c831afb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,6 @@ export default function commonjs(options: Options = {}): Plugin { let dynaimcRequire: DynaimcRequire return { - apply: 'serve', name: 'vite-plugin-commonjs', configResolved(_config) { config = _config @@ -199,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/build.test.ts b/test/build.test.ts new file mode 100644 index 0000000..e69de29 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; }