-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
77 lines (72 loc) · 1.89 KB
/
build.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
const esbuild = require("esbuild");
const Fs = require("fs");
Fs.watchFile("lib/ui.html", (curr, prev) => {
buildTemplate();
});
function buildTemplate() {
const template = Fs.readFileSync("lib/ui.html", "utf8");
const js = Fs.readFileSync("dist/ui.js", "utf8");
const hyperscript = Fs.readFileSync(
"node_modules/hyperscript.org/dist/_hyperscript.min.js",
"utf8",
);
const css = Fs.readFileSync("dist/ui.css", "utf8");
console.log("Rebuilt template");
const replaced = template
.replace("__JSSCRIPT__", js)
.replace("__HYPERSCRIPT__", hyperscript)
.replace("__CSSSTYLE__", css);
Fs.writeFileSync("dist/ui.html", replaced);
}
esbuild
.build({
entryPoints: ["lib/ui.css"],
bundle: true,
watch: true,
outfile: "dist/ui.css",
loader: {
".png": "dataurl",
},
logLevel: "info",
watch: {
onRebuild(error, result) {
if (error) console.error("watch build (ui) failed:", error);
else console.log("watch build (ui) succeeded:", result);
buildTemplate();
},
},
})
.catch(() => process.exit(1));
esbuild
.build({
entryPoints: ["lib/ui.ts"],
bundle: true,
watch: true,
outfile: "dist/ui.js",
logLevel: "info",
watch: {
onRebuild(error, result) {
if (error) console.error("watch build (ui) failed:", error);
else console.log("watch build (ui) succeeded:", result);
buildTemplate();
},
},
})
.catch(() => process.exit(1));
esbuild
.build({
entryPoints: ["lib/backend.ts"],
bundle: true,
watch: true,
outfile: "dist/backend.js",
logLevel: "info",
target: "es6",
watch: {
onRebuild(error, result) {
if (error) console.error("watch build (code) failed:", error);
else console.log("watch build (code) succeeded:", result);
buildTemplate();
},
},
})
.catch(() => process.exit(1));