-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathesbuild.mjs
More file actions
139 lines (126 loc) · 3.19 KB
/
esbuild.mjs
File metadata and controls
139 lines (126 loc) · 3.19 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env node
import process from "process";
import * as esbuild from "esbuild";
import copy from "esbuild-plugin-copy";
const watch = process.argv.includes("--watch");
const minify = process.argv.includes("--minify");
const disable_sourcemap = process.argv.includes("--sourcemap=no");
const sourcemap_client = disable_sourcemap ? null : { sourcemap: "inline" };
const sourcemap_view = disable_sourcemap ? null : { sourcemap: "inline" };
if (watch) console.log("Watch mode enabled, rebuilding on file change...");
const watchPlugin = (fileName) => {
return {
name: "log build status",
setup(build) {
build.onEnd(result => {
const errCount = result.errors.length;
if (errCount > 0) {
console.error(`❌ Build for ${fileName} failed with ${errCount} error${errCount > 1 ? "s" : ""}`);
} else {
console.log(`✅ Build finished for ${fileName}`);
}
});
}
};
}
// Build prosemirror editor.
const fontLoader = "copy";
const editorConfig = {
entryPoints: ["./editor/src/index.ts"],
bundle: true,
outdir: "./editor_output",
...sourcemap_client,
platform: "browser",
loader: {
".woff": fontLoader,
".woff2": fontLoader,
".ttf": fontLoader,
".grammar": "file"
},
minify,
plugins: [watchPlugin("editor")]
};
if (!watch) {
esbuild.build(editorConfig);
} else {
const ctx = await esbuild.context(editorConfig);
ctx.watch();
}
const nodeConfig = {
entryPoints: ["./src/mainNode.ts"],
bundle: true,
...sourcemap_client,
format: "cjs",
platform: "node",
external: ["vscode"],
outfile: "out/src/mainNode.js",
minify,
loader: {
".html": "text",
},
plugins: [watchPlugin("extension/node")]
};
// Build of the VS Code extension, for electron (hence cjs + node)
if (!watch) {
esbuild.build(nodeConfig);
} else {
const ctx = await esbuild.context(nodeConfig);
ctx.watch();
}
const browserConfig = {
entryPoints: ["./src/mainBrowser.ts"],
bundle: true,
...sourcemap_client,
format: "cjs",
platform: "browser",
external: ["vscode", "child_process"],
outfile: "out/src/mainBrowser.js",
minify,
loader: {
".html": "text",
},
plugins: [
copy({
assets: {
from: ['./vendor/*.zip', './vendor/*.bc', './vendor/*.js', './vendor/*.wasm'],
to: ['..'],
},
keepStructure: false,
}),
watchPlugin("extension/browser"),
]
};
// Build browser sources:
if (!watch) {
esbuild.build(browserConfig);
} else {
const ctx = await esbuild.context(browserConfig);
ctx.watch();
}
const viewConfig = (file) => {
return {
entryPoints: [file],
bundle: true,
...sourcemap_view,
platform: "browser",
outdir: "out",
outbase: ".",
minify,
plugins: [watchPlugin(file)]
}
};
// Build of the VS Code view, for modern Chrome (webview)
async function viewBuild(file) {
if (!watch) {
esbuild.build(viewConfig(file));
} else {
const ctx = await esbuild.context(viewConfig(file));
ctx.watch();
}
}
viewBuild("./views/goals/index.tsx");
viewBuild("./views/execute/index.tsx");
viewBuild("./views/debug/index.tsx");
viewBuild("./views/search/index.tsx");
viewBuild("./views/symbols/index.tsx");
viewBuild("./views/tactics/index.tsx");