Skip to content

Commit 83c7c7f

Browse files
authored
fix: support swc target for mjs (#1081)
1 parent 8c26e63 commit 83c7c7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/plugins/swc-target.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ModuleConfig } from '@swc/core/types';
12
import { PrettyError } from '../errors'
23
import { Plugin } from '../plugin'
34
import { localRequire } from '../utils'
@@ -23,7 +24,7 @@ export const swcTarget = (): Plugin => {
2324
},
2425

2526
async renderChunk(code, info) {
26-
if (!enabled || !/\.(cjs|js)$/.test(info.path) || this.format !== 'cjs') {
27+
if (!enabled || !/\.(cjs|mjs|js)$/.test(info.path)) {
2728
return
2829
}
2930
const swc: typeof import('@swc/core') = localRequire('@swc/core')
@@ -55,6 +56,9 @@ export const swcTarget = (): Plugin => {
5556
}
5657
: undefined,
5758
},
59+
module: {
60+
type: this.format === 'cjs' ? 'commonjs' : 'es6'
61+
} as ModuleConfig,
5862
})
5963
return {
6064
code: result.code,

0 commit comments

Comments
 (0)