Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
fix: rewrite bundled extensions to mjs for esm build (#86)
Browse files Browse the repository at this point in the history
The current `index.mjs` re-exports from the CJS `.js` files instead of
the ESM `.mjs` files:
https://unpkg.com/browse/tupleson@0.23.0/lib/index.mjs. I guess tsup
does not rewrite the extensions. This PR adds an esbuild plugin to
rewrite the extensions for the ESM build.
  • Loading branch information
sachinraja authored Nov 8, 2023
1 parent 4ea5cbd commit 9bf904f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

0 comments on commit 9bf904f

Please sign in to comment.