-
Notifications
You must be signed in to change notification settings - Fork 42
/
esbuild.mjs
119 lines (112 loc) · 3.27 KB
/
esbuild.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
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
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import process from "process";
import * as esbuild from "esbuild";
import { sassPlugin } from "esbuild-sass-plugin";
let watchConfig = (entry) => {
return {
onRebuild(error, result) {
console.log(`[watch] build started (rebuild for ${entry})`);
if (error) {
error.errors.forEach((error) =>
console.error(
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
)
);
} else console.log(`[watch] build finished (rebuild for ${entry}`);
},
};
};
let watch = process.argv.includes("--watch") ? watchConfig : (entry) => false;
let minify = process.argv.includes("--minify");
let disable_sourcemap = process.argv.includes("--sourcemap=no");
let sourcemap = disable_sourcemap ? null : { sourcemap: "inline" };
let sourcemap_view = disable_sourcemap ? null : { sourcemap: "inline" };
let enableMeta = false
// Backend build, WASM worker.
var backendEntry = "./backend/wasm/wacoq_worker.ts"
var backend = esbuild
.build({
entryPoints: [backendEntry],
bundle: true,
platform: "browser",
format: "esm",
outdir: "dist",
inject: ["./backend/wasm/shims/process-shim.js",
"./backend/wasm/shims/buffer-shim.js"
],
define: {
global: "self"
},
metafile: enableMeta,
...sourcemap,
minify,
// watch: watch(frontEndEntry),
})
.then((res) => {
if(enableMeta) fs.writeFileSync('backend-meta.json', JSON.stringify(res.metafile));
console.log(`[watch] build finished for ${backendEntry}`);
})
.catch((exn) => {
console.log(exn);
process.exit(1)}
);
// Frontend build, for modern Chrome
var frontEndEntry = "./frontend/classic/js/index.js"
var frontend = esbuild
.build({
entryPoints: [frontEndEntry],
bundle: true,
...sourcemap,
platform: "browser",
format: "esm",
loader: {
'.png': 'binary',
'.svg': 'dataurl'
},
metafile: enableMeta,
outdir: "dist/frontend",
minify,
// watch: watch(frontEndEntry),
plugins: [sassPlugin()]
})
.then((res) => {
if(enableMeta) fs.writeFileSync('frontend-meta.json', JSON.stringify(res.metafile));
console.log(`[watch] build finished for ${frontEndEntry}`);
})
.catch((exn) => {
console.log(exn);
process.exit(1)}
);
function viewBuild(name, dir, file) {
return esbuild
.build({
entryPoints: [path.join(dir, file)],
bundle: true,
...sourcemap_view,
platform: "browser",
outdir: path.join("dist/frontend", name),
outbase: dir,
minify,
loader: {
'.png': 'binary',
'.svg': 'dataurl'
},
metafile: enableMeta,
// watch: watch(file),
})
.then((res) => {
if(enableMeta) fs.writeFileSync(name + '-meta.json', JSON.stringify(res.metafile));
console.log(`[watch] build finished for ${file}`);
})
.catch((exn) => {
console.log(exn);
process.exit(1)
}
);
}
var infoView = viewBuild("info-view", "./vendor/coq-lsp/editor/code/views/info/", "index.tsx");
var infoViewCss = viewBuild("info-view", "./frontend/views/info/", "iframe.css");
// TODO: run serve if --serve was passed.
await Promise.all([frontend, backend, infoView, infoViewCss])