-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ts
More file actions
51 lines (45 loc) · 1.31 KB
/
Copy pathbuild.ts
File metadata and controls
51 lines (45 loc) · 1.31 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
import * as esbuild from "npm:esbuild"
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader"
import type { BuildOptions } from "npm:esbuild"
const args = Deno.args
const watchMode = args.includes("--watch")
const buildOptions: BuildOptions = {
plugins: [...denoPlugins()],
conditions: ["browser", "deno", "node"],
entryPoints: [
"./src/examples/browser/signalingClient.ts",
],
outfile: "./static/js/clientside.js",
bundle: true,
format: "esm",
target: ["es2020"],
define: {
"import.meta.url": '""',
"import.meta": "false",
},
}
async function build() {
try {
const timestamp = new Date().toLocaleTimeString()
await esbuild.build(buildOptions)
console.log(`[${timestamp}] Build completed successfully`)
} catch (error) {
console.error(`Build failed:`, error)
}
}
if (watchMode) {
// Use Deno's built-in watch functionality
const watcher = Deno.watchFs(["./src"], { recursive: true })
// Initial build
await build()
console.log("Watching for changes...")
for await (const event of watcher) {
if (["create", "modify"].includes(event.kind)) {
console.log(`Changes detected in ${event.paths}`)
await build()
}
}
} else {
await build()
esbuild.stop()
}