commit 540ff42219dfb6a76d6cd86bd99a458fc54f1b23
parent 16752f42e1aa7bbf5938e7e3b119d273c9f89942
Author: hrryt <harry@mayesfield.uk>
Date: Tue, 28 Jul 2026 15:00:46 +0100
Add live reload via serve.mjs
Diffstat:
4 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/build.mjs b/build.mjs
@@ -1,15 +1,7 @@
import * as esbuild from 'esbuild'
+import config from './esbuild.json' with { type: "json" };
-await esbuild.build({
- entryPoints: ['src/scripts/index.js'],
- bundle: true,
- minify: true,
- sourcemap: true,
- outdir: 'www/js',
-})
+config.define = { IS_PRODUCTION: 'true' };
+config.minify = true;
-await esbuild.build({
- entryPoints: ['src/styles/index.css'],
- bundle: true,
- outdir: 'www/css',
-})
+await esbuild.build(config);
diff --git a/esbuild.json b/esbuild.json
@@ -0,0 +1,8 @@
+{
+ "entryPoints": [
+ { "out": "js/index", "in": "src/scripts/index.js" },
+ { "out": "css/index", "in": "src/styles/index.css" }
+ ],
+ "bundle": true,
+ "outdir": "www"
+}
diff --git a/serve.mjs b/serve.mjs
@@ -0,0 +1,13 @@
+import * as esbuild from 'esbuild';
+import config from './esbuild.json' with { type: "json" };
+
+config.define = { IS_PRODUCTION: 'false' };
+config.sourcemap = true;
+
+let ctx = await esbuild.context(config);
+
+await ctx.watch();
+
+let { hosts, port } = await ctx.serve({
+ servedir: 'www',
+});
diff --git a/src/scripts/index.js b/src/scripts/index.js
@@ -1,2 +1,6 @@
import './auto-maths.js';
import './react-roots.js';
+
+if (!IS_PRODUCTION) {
+ new EventSource('/esbuild').addEventListener('change', () => location.reload())
+}