Skip to content

Commit

Permalink
Merge pull request #29 from vite-plugin/v0.8.0
Browse files Browse the repository at this point in the history
V0.8.0
  • Loading branch information
yejimeiming committed Jun 24, 2023
2 parents b4e7476 + ac6988f commit ef781ec
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
5 changes: 5 additions & 0 deletions 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`
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
Empty file added test/build.test.ts
Empty file.
12 changes: 1 addition & 11 deletions 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;
}
Expand Down

0 comments on commit ef781ec

Please sign in to comment.