-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
92 lines (87 loc) · 2.67 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
86
87
88
89
90
91
92
const { copy: esbuildPluginCopy } = require("esbuild-plugin-copy");
const esbuild = require("esbuild");
const {
esbuildProblemMatcherPlugin,
} = require("./plugins/esbuildProblemMatchersPlugin");
const { injectionPlugin } = require("./plugins/injection-plugin");
const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
const commonBuildOptions = {
bundle: true,
format: "esm",
target: "es2015",
minify: production,
sourcesContent: false,
logLevel: "silent",
alias: {
react: "preact/compat",
},
allowOverwrite: true,
};
async function main() {
const contexts = [];
// Build the visualization webview code
contexts.push(
await esbuild.context({
...commonBuildOptions,
entryPoints: ["src/index.tsx"],
outfile: "./dist/bundle/index.js",
plugins: [
esbuildPluginCopy({
// Resolve relative to the current working directory
resolveFrom: "cwd",
assets: [
{
from: ["./public/**/*"],
to: ["./dist"],
watch: watch,
},
],
}),
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
}),
);
// Build the initial resources (JS and CSS)
contexts.push(
await esbuild.context({
...commonBuildOptions,
entryPoints: ["src/initial-resources/index.ts"],
outfile: "./dist/bundle/initial.js",
plugins: [
injectionPlugin({
inFile: "src/index.ejs",
outFile: "dist/index.html",
}),
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
}),
);
// Build the service worker
contexts.push(
await esbuild.context({
...commonBuildOptions,
format: "iife",
entryPoints: ["src/service-worker.ts"],
outdir: "./dist",
platform: "browser",
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
}),
);
if (watch) {
await Promise.allSettled(contexts.map((context) => context.watch()));
} else {
await Promise.allSettled(
contexts.map((context) => context.rebuild().then(context.dispose)),
);
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});