This example demonstrates how to integrate a TypeScript Web Component bundle into a Datapages project using esbuild through a custom watcher, so edits to .ts, .templ, and .go all hot-reload through datapages watch.
The example is a minimal "flash sale" landing page with 2 Web Components:
<wc-counter>— a vanilla shadow-DOM custom element with no runtime dependencies.<wc-particles>— built with Lit.
wcexample.mp4
The datapages.yaml defines a custom watcher that runs esbuild whenever any TypeScript source in js/src/ changes:
custom-watchers:
- name: "Bundle web components (esbuild)"
include:
- "js/src/**/*.ts"
cmd: "cd js && node build.mjs"
fail-on-error: true
requires: reloadjs/build.mjs bundles js/src/index.ts into app/static/bundle.js. The page references it via assets.Path("bundle.js") so the URL is consistent in dev and production.
In dev mode, static files are served directly from ./app/static/ on disk, so a fresh bundle is picked up on browser reload without needing to rebuild and restart the server. In production, app/static/ is embedded into the binary.
- Go (see
go.modfor the required version) - Node.js (for esbuild and Lit)
# Install JS dependencies (esbuild, TypeScript, Lit).
make npm-installmake devThe Datapages watcher proxy starts at http://localhost:7331. The app itself listens on http://localhost:8080. To change that, set HOST and PORT in the shell that runs make dev, and watch.app-host in datapages.yaml to match.
Edit any file under js/src/ — esbuild rebuilds the bundle and the browser reloads.