Skip to content

Developing locally ​

The `smite dev` loop: generators, a node:http server, and auto-reload.

package @smitejs/cli

smite dev is the local-development loop for a single app. It replaces the hand-rolled createServer boilerplate of the first examples with one command that regenerates, bundles, serves, and reloads.

What it does ​

  1. Loads smite.config.ts and compiles the app entries in collect mode.
  2. Runs every plugin in the config — typed client, OpenAPI, anything you add.
  3. Bundles a runtime server over node:http and spawns it as a child node process.
  4. Watches the sources; on change it re-runs the generators, rebundles with esbuild, and restarts the server.

Keeping the CLI free of generators ​

@smitejs/cli never imports @smitejs/http or the generator packages. The dev server is a generated entry that imports your app and serveNode from the packages you installed; esbuild bundles it at ALLOW_GLOBAL_REGISTRY: "false" and a child process runs it. The watcher skips generated artifacts (*.client.ts, openapi.json) so regeneration never re-triggers a rebuild.

ts
await bundleDevServer({
  cwd,
  entry,
  alias: sourceAliases,
  outfile,
});
ts
"globalRegistry"

Watching ​

The watcher fingerprints file mtimes and sizes on a poll interval — portable, no native dependencies — and fires once per change batch.

ts
const watcher = new DevWatcher({
  watch: async () => [join(dir, "file.txt")],
  intervalMs: 20,
  onChange: (paths) => changed.push(...paths),
});
await watcher.poll();
ts
[]
[join(dir, "file.txt")]

Generators ​

Every plugin declared in the config runs on each cycle, in declaration order.

ts
await runAll(plugins, { apps: [] });
ts
["first", "second"]

Extending the server ​

The scaffolded src/server.ts calls serveNode directly, so you can mount extra routers (docs), rewrite requests (transformRequest), or swap the listener — the dev loop and your production server share one adapter.

Released under the MIT License.

/ search•[ ] prev/next•j/k scroll•h home•t theme•guide/techniques/developing-locally