-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathesbuild.mjs
More file actions
59 lines (54 loc) · 1.36 KB
/
esbuild.mjs
File metadata and controls
59 lines (54 loc) · 1.36 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
// @ts-check
import { context, build } from "esbuild";
const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
/** @type {import("esbuild").Plugin} */
const logRebuildPlugin = {
name: "log-rebuild",
setup(build) {
build.onEnd((result) => {
if (result.errors.length > 0) {
console.error(`Build failed with ${result.errors.length} error(s)`);
} else {
console.log(`Build succeeded at ${new Date().toLocaleTimeString()}`);
}
});
},
};
/** @type {import("esbuild").BuildOptions} */
const buildOptions = {
entryPoints: ["src/extension.ts"],
bundle: true,
outfile: "dist/extension.js",
platform: "node",
target: "node20",
format: "cjs",
mainFields: ["module", "main"],
alias: {
// Force openpgp to use CJS. The ESM version uses import.meta.url which is
// undefined when bundled to CJS, causing runtime errors.
openpgp: "./node_modules/openpgp/dist/node/openpgp.min.cjs",
},
external: ["vscode", "@napi-rs/keyring"],
sourcemap: production ? "external" : true,
minify: production,
plugins: watch ? [logRebuildPlugin] : [],
loader: {
".sh": "text",
".ps1": "text",
},
};
async function main() {
if (watch) {
const ctx = await context(buildOptions);
await ctx.watch();
} else {
await build(buildOptions);
}
}
try {
await main();
} catch (err) {
console.error(err);
process.exit(1);
}