Skip to content

Commit

Permalink
fix: support swc target for mjs (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydnhkim committed Feb 10, 2024
1 parent 8c26e63 commit 83c7c7f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plugins/swc-target.ts
@@ -1,3 +1,4 @@
import type { ModuleConfig } from '@swc/core/types';
import { PrettyError } from '../errors'
import { Plugin } from '../plugin'
import { localRequire } from '../utils'
Expand All @@ -23,7 +24,7 @@ export const swcTarget = (): Plugin => {
},

async renderChunk(code, info) {
if (!enabled || !/\.(cjs|js)$/.test(info.path) || this.format !== 'cjs') {
if (!enabled || !/\.(cjs|mjs|js)$/.test(info.path)) {
return
}
const swc: typeof import('@swc/core') = localRequire('@swc/core')
Expand Down Expand Up @@ -55,6 +56,9 @@ export const swcTarget = (): Plugin => {
}
: undefined,
},
module: {
type: this.format === 'cjs' ? 'commonjs' : 'es6'
} as ModuleConfig,
})
return {
code: result.code,
Expand Down

0 comments on commit 83c7c7f

Please sign in to comment.