You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is recommended to use some level of template processing over raw string templates so that HTML is well-formed and variable values are properly escaped. Here is a more realistic TypeScript example that uses [`preact`](https://preactjs.com/) with [`htm`](https://github.com/developit/htm) and `domstack` page introspection.
If your `src` folder doesn't have a `root.layout.js` file somewhere in it, `domstack` will use the default [`default.root.layout.js`](./lib/defaults/default.root.layout.js) file it ships. The default `root` layout includes a special boolean variable called `defaultStyle` that lets you disable a default page style (provided by [mine.css](http://github.com/bcomnes/mine.css)) that it ships with.
-**Global data** - Derived variables from `global.data.js`, stamped onto every page after all pages initialize (resolved once, after page init)
1438
1457
1458
+
### Watch Mode
1459
+
1460
+
When you run `domstack --watch` (or `domstack -w`), domstack performs an initial build and then watches for changes, rebuilding only what's necessary. Watch mode uses two independent watch loops:
1461
+
1462
+
**esbuild watch** — JS and CSS bundles are handled by esbuild's native `context.watch()`. In watch mode, output filenames are stable (no content hashes), so bundle changes never require a page HTML rebuild. Browser-sync detects the updated files on disk and reloads the browser directly.
1463
+
1464
+
**chokidar watch** — Page files, layouts, templates, and config files are watched by chokidar. When a file changes, domstack determines the minimal set of pages to rebuild using dependency tracking maps built at startup.
1465
+
1466
+
#### What triggers what
1467
+
1468
+
| Change | Rebuild scope |
1469
+
|---|---|
1470
+
|`page.js`, `page.ts`, `page.html`, `page.md`, or `page.vars.*`| Only that page |
1471
+
| A file imported by a `page.js` or `page.vars.*`| Only the pages that import it (transitively) |
1472
+
| A layout file (`*.layout.js`) | Only the pages using that layout |
1473
+
| A file imported by a layout | Only the pages using the affected layout(s) |
1474
+
| A template file (`*.template.js`) | Only that template |
1475
+
| A file imported by a template | Only the affected template(s) |
1476
+
|`markdown-it.settings.*`| All `.md` pages |
1477
+
|`global.data.*`| All pages and templates |
1478
+
|`global.vars.*` or `esbuild.settings.*`| Full rebuild (esbuild restart + all pages) |
1479
+
|`client.js`, `style.css`, `*.layout.css`, `*.layout.client.*`, `global.client.*`, `global.css`, `*.worker.*`| esbuild handles it — no page rebuild |
1480
+
| Adding or removing an esbuild entry point (e.g. creating a new `client.js`) | esbuild restart + only the affected page(s) |
1481
+
| Adding or removing any other file | Full rebuild |
1482
+
1483
+
#### Dependency tracking
1484
+
1485
+
domstack uses [`@11ty/dependency-tree-typescript`](https://github.com/11ty/dependency-tree-typescript) to statically analyze ESM imports in page files, layout files, and template files. This means if your `page.js` imports a shared utility module, changing that module will only rebuild the pages that depend on it — not the entire site.
1486
+
1487
+
esbuild tracks its own entry point dependencies independently. Changing a file imported by `client.js` will trigger an esbuild rebundle but will not trigger a page rebuild, since watch mode uses stable filenames.
1488
+
1489
+
#### Stable filenames
1490
+
1491
+
In watch mode, esbuild uses `[dir]/[name]` output patterns instead of `[dir]/[name]-[hash]`. This means the `<script>` and `<link>` tags in page HTML always point to the same filenames. When esbuild rebundles, the file contents change but the filenames don't, so page HTML never needs to be re-rendered just because a bundle changed.
1492
+
1493
+
#### Build serialization
1494
+
1495
+
Chokidar events are serialized through a promise chain, so rapid saves don't cause overlapping rebuilds. Each rebuild completes before the next one starts.
1496
+
1439
1497
## Roadmap
1440
1498
1441
-
`domstack` works and has a rudimentary watch command, but hasn't been battle tested yet.
1499
+
`domstack` works and has a watch command with progressive rebuilds.
1442
1500
If you end up trying it out, please open any issues or ideas that you have, and feel free to share what you build.
1443
1501
1444
1502
Some notable features are included below, see the [roadmap](https://github.com/users/bcomnes/projects/3/) for a more in depth view of whats planned.
@@ -1480,6 +1538,9 @@ Some notable features are included below, see the [roadmap](https://github.com/u
1480
1538
-[x] markdown-it.settings.ts support
1481
1539
-[x] page-worker.worker.ts page worker support
1482
1540
-[x]`page.md` page support
1541
+
-[x] Remove `postVars` and implement `global.data.{j,t}s`
1542
+
-[x] Harden behavior around conflicting `browserVars` and esbuild settings
1543
+
-[x] Progressive watch rebuilds with dependency tracking
0 commit comments