-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.config.ts
29 lines (28 loc) · 972 Bytes
/
build.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { mkdir, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({
rollup: {
inlineDependencies: true,
},
externals: ["@cloudflare/workers-types", "bun", "@deno/types", "uWebSockets.js"],
hooks: {
async "build:done"(ctx) {
const entries = Object.keys(ctx.pkg.exports || {})
.filter((key) => key.startsWith("./"))
.map((key) => key.slice(2));
for (const entry of entries) {
const dst = join(ctx.options.rootDir, entry + ".d.ts");
console.log(">", dst);
await mkdir(dirname(dst), { recursive: true });
const relativePath =
("..".repeat(entry.split("/").length - 1) || ".") + `/dist/${entry}`;
await writeFile(
dst,
`export * from "${relativePath}";\nexport { default } from "${relativePath}";\n`,
"utf8",
);
}
},
},
});