-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.js
More file actions
64 lines (56 loc) · 1.55 KB
/
build.js
File metadata and controls
64 lines (56 loc) · 1.55 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
const baseConfig = {
entryPoints: ["./src/Index.bs.js"],
minify: true,
bundle: true,
loader: { ".js": "jsx" },
plugins: [],
sourcemap: true,
platform: "browser",
target: ["es2018"],
};
const builds = [
{ format: "esm", outfile: "dist/index.mjs" },
{ format: "cjs", outfile: "dist/index.js" },
];
async function main() {
try {
// Ensure dist directory exists
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist", { recursive: true });
}
// Copy type definitions to dist
const typeDefSource = path.join(__dirname, "src/index.d.ts");
const typeDefDest = path.join(__dirname, "dist/index.d.ts");
if (fs.existsSync(typeDefSource)) {
fs.copyFileSync(typeDefSource, typeDefDest);
console.log("✓ Type definitions copied to dist");
} else {
console.warn(
"⚠ Warning: Type definitions file not found at src/index.d.ts"
);
}
// Run builds in parallel
await Promise.all(
builds.map(async ({ format, outfile }) => {
try {
await esbuild.build({
...baseConfig,
format,
outfile,
});
console.log(`✓ Built ${format} bundle: ${outfile}`);
} catch (error) {
throw new Error(`Failed to build ${format} bundle: ${error.message}`);
}
})
);
console.log("✓ Build completed successfully");
} catch (error) {
console.error("Build failed:", error);
process.exit(1);
}
}
main();