API Reference

dev()

Create a Reactus development engine with Vite middleware and hot reload support.

Create a Reactus development engine with Vite middleware and hot reload support.

ts
import { dev } from 'reactus';

const engine = dev({
  cwd: process.cwd(),
  basePath: '/',
  clientRoute: '/client'
});

Use dev() when you want to:

  • render pages directly from source files
  • run Vite middleware through your server
  • use React fast refresh and Vite transforms during development

Common properties

The returned object exposes:

PropertyDescription
configFinal merged configuration.
pathsBuilt path settings from the underlying Server.
routesRoute prefixes such as the client route.
templatesActive client, document, and page templates.
viteConfigOriginal Vite config passed into ServerResource.
sizeCurrent manifest size.
serverThe underlying Server instance.

Common methods

http(req, res)

Pass a request through Vite and Reactus middleware.

ts
await engine.http(req, res);
if (res.headersSent) return;

Use this before your own route handling.

render(entry, props?)

Render a page entry to final HTML.

ts
const html = await engine.render('@/pages/home', { title: 'Home' });

set(entry)

Add an entry to the manifest and return its Document.

ts
const document = await engine.set('@/pages/home');

renderHMR(entry)

Return the transformed HMR client module for a page entry.

ts
const code = await engine.renderHMR('@/pages/home');

absolute(entry) and id(entry)

Resolve a page entry to its absolute source path or generated document id.