NatUI
API

@natui/dev

Start and control the NatUI development server programmatically.

The @natui/dev package exposes the same state-preserving development server used by the natui dev command. It is a separate package because it owns the rollup, Babel, and esbuild toolchain, which a shipped application has no reason to install. natui dev loads it on demand and asks you to install it when missing. The command chooses its entry in this order: a positional argument, entry from natui.app.json, then src/main.tsx. Programmatic callers pass the resolved entry directly.

createDevServer

import { createDevServer } from '@natui/dev';

const server = await createDevServer({
  root: process.cwd(),
  entry: 'src/main.tsx',
});

const close = async () => {
  await server.close();
};

process.once('SIGINT', () => void close());
process.once('SIGTERM', () => void close());

The watcher keeps the process alive. The signal handlers use the returned server handle to cleanly stop the watcher and native host.

The executable entry must call run() once. The server watches the application's local source graph, applies React Fast Refresh after successful builds, and keeps the previous native UI mounted after a build or evaluation error.

Prop

Type

PropertyPurpose
entryExecutable entry path, relative to root unless absolute
rootProject root for module resolution and the watcher
logReceives build, mount, refresh, and error status text

NatuiDevServer

Prop

Type

close() stops the build watcher, unmounts React, asks the native host to quit, and removes temporary build output. Calling it more than once is safe.

The server runs its module builder in-process and does not open an HTTP port.

On this page