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

fix: support swc target for mjs #1081

Merged
merged 1 commit into from Feb 10, 2024
Merged
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
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