-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ts
68 lines (62 loc) · 1.7 KB
/
build.ts
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
/**
* Builds a TypeScript file to a directory.
* @param filePath The file path.
* @param outputDir Directory to output the compiled file.
* @param minify Whether or not to minify the compiled output. Useful for debugging.
* @returns void
*/
export async function compile(
filePath: string,
outputDir: string
): Promise<any> {
let output = (await Bun.build({
entrypoints: [filePath],
outdir: outputDir,
splitting: true,
emitDCEAnnotations: true,
sourcemap: "linked",
minify: {
identifiers: true,
syntax: true,
whitespace: true,
},
}).catch((e) => {
console.error("Failed to build:", e);
})) as BuildOutput;
if (output.logs) {
for (const log of output.logs) {
console.error(log.message);
}
}
}
import { join } from "path";
import { watch } from "fs";
import * as sass from "sass";
import type { BuildOutput } from "bun";
async function build() {
try {
await compile("./src/main.ts", "./public/dist/");
await compile("./src/jfl-demo.ts", "./public/dist/");
await compile("./src/api.ts", "./public/dist/");
} catch (e) {
console.log(e);
}
try {
const mainScss = sass.compile("./src/scss/main.scss");
await Bun.write("./public/dist/main.css", mainScss.css);
// const landingScss = sass.compile("./src/scss/landing.scss");
// await Bun.write("./public/landing.css", landingScss.css);
} catch (_) {
console.error(_);
}
}
const watcher = watch(
join(import.meta.dir, "./src"),
{ recursive: true },
async (event, filename) => {
console.log(`Detected ${event} in ${filename}`);
build();
}
);
console.log("Watching!");
build();