Skip to content

Commit c8f1683

Browse files
authored
Bun bundler (#4)
* chore: remove rollup * chore: mark package as module * chore: add bun as dependency * feat: add build options * feat: add build script * chore: lock deps * chore: fix import path
1 parent eaa4cbf commit c8f1683

File tree

5 files changed

+74
-516
lines changed

5 files changed

+74
-516
lines changed

build.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import bunfig from "./bunfig.toml";
2+
import pkg from "./package.json";
3+
import { join } from "path";
4+
import { mkdir, rename, cp, rm } from "fs/promises";
5+
6+
await rm(bunfig.build.outdir, { recursive: true, force: true });
7+
await mkdir(bunfig.build.outdir, { recursive: true });
8+
9+
await Promise.all([esm(), cjs(), types()]);
10+
11+
function cjs() {
12+
return Bun.build({ ...bunfig.build, format: "cjs" });
13+
}
14+
15+
async function esm() {
16+
await Bun.build({ ...bunfig.build, format: "esm" });
17+
const jsPath = join(bunfig.build.outdir, "index.js");
18+
const mjsPath = join(process.cwd(), pkg.module);
19+
return rename(jsPath, mjsPath);
20+
}
21+
22+
function types() {
23+
const srcTypesPath = join(process.cwd(), "src/types.ts");
24+
const outTypesPath = join(process.cwd(), pkg.types);
25+
return cp(srcTypesPath, outTypesPath);
26+
}

0 commit comments

Comments
 (0)