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

Commit 9bf904f

Browse files
authored
fix: rewrite bundled extensions to mjs for esm build (#86)
The current `index.mjs` re-exports from the CJS `.js` files instead of the ESM `.mjs` files: https://unpkg.com/browse/[email protected]/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.
1 parent 4ea5cbd commit 9bf904f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tsup.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,20 @@ export default defineConfig({
77
entry: ["src/**/*.ts", "!src/**/*.test.*"],
88
format: ["cjs", "esm"],
99
outDir: "lib",
10+
plugins: [
11+
{
12+
name: "fix-cjs",
13+
renderChunk(_, chunk) {
14+
if (this.format === "esm") {
15+
// replace `from '...js'` with `from '...mjs'` for mjs imports & exports
16+
const code = chunk.code.replace(
17+
/from ['"](.*)\.js['"]/g,
18+
"from '$1.mjs'",
19+
);
20+
return { code };
21+
}
22+
},
23+
},
24+
],
1025
sourcemap: true,
1126
});

0 commit comments

Comments
 (0)