Created
April 12, 2022 15:41
-
-
Save timm-oh/d6a22ada6c7eda1e4b18de578d9eebd3 to your computer and use it in GitHub Desktop.
Revisions
-
timm-oh created this gist
Apr 12, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ #!/usr/bin/env node import esbuild from "esbuild" import chokidar from "chokidar" import http from "http" const watchDirectories = [ "./app/assets/builds/*", "./app/views/**/*.erb", ] const watch = process.argv.includes("--watch") const clients = [] const config = { entryPoints: ["app/assets/javascript/application.js"], bundle: true, outdir: "app/assets/builds", watch: watch, banner: { js: ' (() => new EventSource("http://localhost:8082").onmessage = () => location.reload())();', }, } if (watch) { (async () => { await esbuild.build(config); chokidar.watch(watchDirectories).on('all', (event, path) => { console.log(`rebuilding ${path}`) clients.forEach((res) => res.write('data: update\n\n')) clients.length = 0 }) })(); 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); } else { esbuild .build(config) .catch(error => { console.log(error) process.exit(1) }) } // Anything Vendor related esbuild.build({ entryPoints: ["vendor/blazer/javascript/application.js"], bundle: true, outfile: "app/assets/builds/blazer/application.js", watch: process.argv.includes("--watch") }).catch(error => { console.log(error) process.exit(1) })