Skip to content

Commit 738a78d

Browse files
committed
parallelize build codes
1 parent 37b184f commit 738a78d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

build/dev.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This code is Deno only
22

3+
import { assert } from "@std/assert/assert";
34
import { exists } from "@std/fs/exists";
45
import * as ESBuild from "esbuild";
56
import { OPTIONS } from "./config.ts";
@@ -9,11 +10,12 @@ const BUILD_OPTIONS: ESBuild.BuildOptions = {
910
minify: false,
1011
define: { LIVE_RELOAD: "true" },
1112
};
12-
if (import.meta.main) {
13-
if (!await exists(new URL("../dictionary/dictionary.ts", import.meta.url))) {
14-
const Dictionary = await import("../dictionary/build.ts");
15-
await Dictionary.build();
16-
}
13+
async function watchMain(): Promise<void> {
14+
const context = await ESBuild.context(BUILD_OPTIONS);
15+
await context.watch();
16+
await context.serve({ servedir: "./dist/" });
17+
}
18+
async function watchDictionary(): Promise<never> {
1719
const command = new Deno.Command(Deno.execPath(), {
1820
args: [
1921
"run",
@@ -32,9 +34,14 @@ if (import.meta.main) {
3234
stdin: "null",
3335
});
3436
const process = command.spawn();
35-
const context = await ESBuild.context(BUILD_OPTIONS);
36-
await context.watch();
37-
await context.serve({ servedir: "./dist/" });
3837
const status = await process.status;
38+
assert(!status.success);
3939
Deno.exit(status.code);
4040
}
41+
if (import.meta.main) {
42+
if (!await exists(new URL("../dictionary/dictionary.ts", import.meta.url))) {
43+
const Dictionary = await import("../dictionary/build.ts");
44+
await Dictionary.build();
45+
}
46+
await Promise.all([watchDictionary(), watchMain()]);
47+
}

0 commit comments

Comments
 (0)