-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathesbuild-dev.config.js
49 lines (45 loc) · 1.23 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
42
43
44
45
46
47
48
49
#!/usr/bin/env node
const path = require("path");
const chokidar = require("chokidar");
const rails = require("esbuild-rails");
const http = require("http");
const clients = [];
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);
async function builder() {
let result = await require("esbuild").build({
entryPoints: ["application.js"],
bundle: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
incremental: true,
banner: {
js: ' (() => new EventSource("http://localhost:8082").onmessage = () => location.reload())();',
},
plugins: [rails()],
});
chokidar
.watch([
"./app/javascript/**/*.js",
"./app/views/**/*.html.haml",
"./app/assets/stylesheets/*.css",
])
.on("all", (event, path) => {
if (path.includes("javascript")) {
result.rebuild();
}
clients.forEach((res) => res.write("data: update\n\n"));
clients.length = 0;
});
}
builder();