-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathesbuild.mjs
74 lines (69 loc) · 1.98 KB
/
esbuild.mjs
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
65
66
67
68
69
70
71
72
73
74
import esbuild from "esbuild";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { nodeExternalsPlugin } from "esbuild-node-externals";
// import { glob } from "glob";
// import path from "path";
const banner = `
// patch __dirname
// import { fileURLToPath } from "url";
// import path from "path";
// const __filename = fileURLToPath(import.meta.url);
// const __dirname = path.dirname(__filename);
// allow top level await
import { createRequire as topLevelCreateRequire } from "module";
const require = topLevelCreateRequire(import.meta.url);
`;
const argv = yargs(hideBin(process.argv))
.usage("Usage: $0 -entry [string] -out [string]")
.option("entry", {
alias: "e",
describe: "Entry point file",
type: "string",
demandOption: true,
})
.option("out", {
alias: "o",
describe: "Output file path",
type: "string",
demandOption: true,
})
.help()
.alias("help", "h").argv;
// generate a list of all package.json files in the monorepo
function getPackagePaths() {
// const packagePaths = [];
// const packageGlob = "package.json";
// const packageJsonFiles = glob.sync(packageGlob);
// for (const packageJsonFile of packageJsonFiles) {
// packagePaths.push(path.dirname(packageJsonFile) + "/package.json");
// }
// return packagePaths;
return ["package.json"];
}
esbuild
.build({
entryPoints: [argv.entry],
bundle: true,
outfile: argv.out,
format: "esm",
banner: {
js: banner,
},
platform: "node",
external: ["body-parser"],
plugins: [
nodeExternalsPlugin({
packagePath: getPackagePaths(),
}),
],
sourcemap: true,
target: "node20",
})
.then(() => {
console.log("Build completed successfully");
})
.catch((error) => {
console.error("Build failed:", error);
process.exit(1);
});