Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.8.0 #29

Merged
merged 3 commits into from Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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