From 98094a5c29e2ddf4afd19327160415a370ec4a41 Mon Sep 17 00:00:00 2001 From: Sachin Raja Date: Sat, 4 Nov 2023 11:08:50 -0700 Subject: [PATCH] fix: rewrite bundled extensions to mjs for esm build --- tsup.config.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tsup.config.ts b/tsup.config.ts index 6624b1d..82f0b2e 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -7,5 +7,20 @@ export default defineConfig({ entry: ["src/**/*.ts", "!src/**/*.test.*"], format: ["cjs", "esm"], outDir: "lib", + plugins: [ + { + name: "fix-cjs", + renderChunk(_, chunk) { + if (this.format === "esm") { + // replace `from '...js'` with `from '...mjs'` for mjs imports & exports + const code = chunk.code.replace( + /from ['"](.*)\.js['"]/g, + "from '$1.mjs'", + ); + return { code }; + } + }, + }, + ], sourcemap: true, });