-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.ts
52 lines (44 loc) · 1.29 KB
/
build.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/// <reference types="bun-types" />
import { generateDtsBundle } from "dts-bundle-generator";
import fs from "fs";
import { dependencies, peerDependencies } from "./package.json";
// Create build folder if not exist
if (!fs.existsSync("./build")) {
fs.mkdirSync("./build");
}
const start = Date.now();
console.log("JSCompiling", "Building...");
await Promise.all([
Bun.build({
entrypoints: ["./index.ts"],
external: Object.keys(dependencies).concat(Object.keys(peerDependencies)),
format: "esm",
minify: true,
outdir: "./build",
naming: "index.esm.js",
sourcemap: "external",
target: "browser"
}),
Bun.build({
entrypoints: ["./index.ts"],
external: Object.keys(dependencies).concat(Object.keys(peerDependencies)),
format: "cjs",
minify: true,
outdir: "./build",
naming: "index.cjs.js",
sourcemap: "external",
target: "node"
})
]);
console.log("JSCompiling", "Done!");
console.log("TypeCompiling", "Building...");
const typedContent = generateDtsBundle([
{
filePath: "./index.ts"
}
]);
// Write typed content to index.d.ts
fs.writeFileSync("./build/index.d.ts", typedContent.join("\n"));
console.log("TypeCompiling", "Done!");
console.log("Build", `Build success, take ${Date.now() - start}ms`);
console.log("Build", "Done!");