From 5e46a22c4673dd94365457cd3d12fff78fe1b56b Mon Sep 17 00:00:00 2001 From: Haydn Date: Sat, 3 Feb 2024 16:38:41 +0900 Subject: [PATCH] fix: support swc target for mjs --- src/plugins/swc-target.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/swc-target.ts b/src/plugins/swc-target.ts index 25aa6d5a..757fc759 100644 --- a/src/plugins/swc-target.ts +++ b/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' @@ -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') @@ -55,6 +56,9 @@ export const swcTarget = (): Plugin => { } : undefined, }, + module: { + type: this.format === 'cjs' ? 'commonjs' : 'es6' + } as ModuleConfig, }) return { code: result.code,