-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathesbuild.js
85 lines (78 loc) · 2.04 KB
/
esbuild.js
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
83
84
85
import dotenv from "dotenv";
import esbuild from "esbuild";
import envFilePlugin from "esbuild-envfile-plugin";
import { sassPlugin } from "esbuild-sass-plugin";
import { typecheckPlugin } from "@jgoz/esbuild-plugin-typecheck";
const isWatchMode = process.argv.includes("watch") || process.argv.includes("-w") || process.argv.includes("--watch");
dotenv.config();
const requiredEnvVars = ["APP_ID", "REDIRECT_URI"];
const missingEnvVars = requiredEnvVars.filter((envVar) => !process.env[envVar]);
if (missingEnvVars.length > 0) {
throw new Error(`Missing environment variables: ${missingEnvVars.join(", ")}`);
}
/**
* @returns {import("esbuild").BuildOptions}
*/
function makeGeneralConfig(label, shouldBundle, platform = null) {
return {
bundle: shouldBundle,
outdir: "/",
outbase: "/",
...(platform !== null ? { platform } : {}),
format: "esm",
sourcemap: true,
}
}
const buildContexts = await Promise.all([
esbuild.context({
entryPoints: [
"src/app.ts",
],
packages: "external",
plugins: [
envFilePlugin,
typecheckPlugin({
watch: isWatchMode,
omitStartLog: true,
})
],
...makeGeneralConfig("Node TS", true, "node")
}),
esbuild.context({
entryPoints: [
"src/static/scripts/main.ts",
"src/static/serviceWorker.ts",
"src/static/scripts/components/mediaViewer/videoPlayer/popoutVideoPlayer/popoutVideoPlayer.ts",
"src/static/analytics/scripts/script.ts",
],
packages: "external",
plugins: [
envFilePlugin,
typecheckPlugin({
watch: isWatchMode,
omitStartLog: true,
})
],
...makeGeneralConfig("Browser TS", true, "browser")
}),
esbuild.context({
entryPoints: [
"src/static/style/main.scss",
"src/static/analytics/style/style.scss",
],
minify: true,
external: ["*.svg"],
plugins: [
sassPlugin({
})
],
...makeGeneralConfig("SCSS", true)
}),
]);
if (isWatchMode) {
await Promise.all(buildContexts.map((cxt) => cxt.watch()));
}
else {
await Promise.all(buildContexts.map((cxt) => cxt.rebuild()));
await Promise.all(buildContexts.map((cxt) => cxt.dispose()));
}