From 2f70e6f3559b265091572c8a4c696bec1075815b Mon Sep 17 00:00:00 2001 From: sigmasternchen Date: Tue, 29 Oct 2024 21:37:07 +0100 Subject: [PATCH] add watch script for esbuild --- package.json | 3 ++- src/build/esbuild.config.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7fa71e6..f334797 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "node src/build/esbuild.config.js" + "build": "node src/build/esbuild.config.js", + "watch": "node src/build/esbuild.config.js --watch" }, "repository": { "type": "git", diff --git a/src/build/esbuild.config.js b/src/build/esbuild.config.js index e250ce4..eba5a78 100644 --- a/src/build/esbuild.config.js +++ b/src/build/esbuild.config.js @@ -1,9 +1,24 @@ import esbuild from "esbuild"; import {bannerIndex} from "./banner-index.js"; -esbuild.build({ +const config = { entryPoints: ['./src/index.ts'], bundle: true, outfile: './html/static/bundle.js', plugins: [bannerIndex], -}).catch(() => process.exit(1)); \ No newline at end of file +}; + +try { + if (process.argv.indexOf("--watch") >= 0) { + const ctx = await esbuild.context(config); + + console.log("Watching..."); + await ctx.watch(); + } else { + console.log("Building..."); + await esbuild.build(config); + } +} catch (e) { + console.error(e); + process.exit(1); +}