From 66ce5ddb9c246f71b42eca271c43fa9d1b0d19a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Mon, 5 Jun 2023 13:59:03 +0800 Subject: [PATCH 1/3] feat: support build --- src/index.ts | 1 - test/build.test.ts | 0 2 files changed, 1 deletion(-) create mode 100644 test/build.test.ts diff --git a/src/index.ts b/src/index.ts index 4bb2a97..95871cd 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 diff --git a/test/build.test.ts b/test/build.test.ts new file mode 100644 index 0000000..e69de29 From bf2f306db5d87ea39f33e46ccdd70b76c81f2771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E9=B8=A1=E6=B2=A1=E5=90=8D?= Date: Sat, 24 Jun 2023 10:37:04 +0800 Subject: [PATCH 2/3] fix: dynamic-require typo #28 --- src/index.ts | 2 +- test/fixtures/__snapshots__/dynamic.tsx | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) 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; } From ac6988fe67fd57e38bb7242309dc37193da4a132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E9=B8=A1=E6=B2=A1=E5=90=8D?= Date: Sat, 24 Jun 2023 11:56:01 +0800 Subject: [PATCH 3/3] v0.8.0 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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",