-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
esbuild.config.mjs
82 lines (76 loc) · 2.18 KB
/
esbuild.config.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
75
76
77
78
79
80
81
82
import fs from "node:fs";
import path from "node:path";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import dotenv from "dotenv";
import esbuild from "esbuild";
dotenv.config();
const args = process.argv.slice(2);
const isWatch = args.includes("--watch");
const isMinify = args.includes("--minify");
const isSourcemap = args.includes("--sourcemap");
const isProduction = args.includes("--production");
const packageJsonPath = path.resolve(process.cwd(), "package.json");
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
const version = pkg.version;
const config = {
entryPoints: ["./src/extension.ts"],
bundle: true,
outfile: "out/extension.js",
external: ["vscode"],
format: "cjs",
platform: "node",
target: "es6",
sourcemap: isSourcemap,
minify: isMinify,
define: {
GLOBAL_SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN ?? null),
GLOBAL_RELEASE_VERSION: isProduction ? JSON.stringify(version) : JSON.stringify("dev"),
},
plugins: [
{
// for VSCode $esbuild-watch problem matcher
name: "esbuild-problem-matcher",
setup(build) {
build.onStart(() => {
console.log("[watch] build started");
});
build.onEnd((result) => {
for (const { text, location } of result.errors) {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
}
console.log("[watch] build finished");
});
},
},
],
};
// Upload source maps to Sentry (only on production build, because it's slow and expensive)
if (isProduction) {
config.plugins.push(
sentryEsbuildPlugin({
org: "yevhenii-hyzyla",
project: "sweetpad",
release: version,
authToken: process.env.SENTRY_AUTH_TOKEN,
disableInstrumenter: true,
}),
);
}
if (isWatch) {
console.log("[watch] build started");
esbuild
.context(config)
.then((ctx) => {
ctx.watch();
console.log("Watching for changes...");
})
.catch(() => process.exit(1));
} else {
esbuild
.build(config)
.then(() => {
console.log("Build completed.");
})
.catch(() => process.exit(1));
}