-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild-dev.config.js
41 lines (36 loc) · 1.03 KB
/
esbuild-dev.config.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
#!/usr/bin/env node
const path = require('path')
const http = require('http')
const watch = process.argv.includes('--watch')
const clients = []
const watchOptions = {
onRebuild: (error, result) => {
if (error) {
console.error('Build failed:', error)
} else {
console.log('Build succeeded')
clients.forEach((res) => res.write('data: update\n\n'))
clients.length = 0
}
}
}
require("esbuild").build({
entryPoints: ["application.js"],
bundle: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
watch: watch && watchOptions,
banner: {
js: ' (() => new EventSource("http://localhost:8082").onmessage = () => location.reload())();',
},
}).catch(() => process.exit(1));
http.createServer((req, res) => {
return clients.push(
res.writeHead(200, {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"Access-Control-Allow-Origin": "*",
Connection: "keep-alive",
}),
);
}).listen(8082);