import esbuild from "esbuild"; import { createServer } from "http"; const clients = []; esbuild .build({ entryPoints: ["./index.tsx"], bundle: true, outfile: "bundle.js", banner: { js: ' (() => new EventSource("http://localhost:8000").onmessage = () => location.reload())();', }, watch: { onRebuild(error) { clients.forEach((res) => res.write("data: update\n\n")); clients.length = 0; console.log(error ? error : "..."); }, }, }) .catch(() => process.exit(1)); 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(8000);