Documentation

Browser-only runtime

DevJar previews and CLI sites run in the browser. Server-only libraries and libraries that require a server runtime are not supported.

Live code APIs

Build your own editor, interactive docs, or shader playground with live React previews.

Render a project with DevJar

The live examples use the DevJar component. Pass project files as strings, connect your editor to the files prop, and watch changes run inside an iframe. Use useDevJar to control your own iframe.

import { DevJar } from 'devjar'const files = {  'pages/index.tsx': `export default function Page() {    return <h1>Hello from devjar</h1>  }`,}function Preview() {  return (    <DevJar files={files} title="Live preview" />  )}

Requires React 19 or newer. Install with npm install devjar. Embedded previews run in the browser; no special hosting headers required.

For a live code editor, pair Devjar with @sugar-high/react. Its Editor component provides syntax highlighting; update files from its onChange callback to refresh the preview. The gallery demos use this combination.

Personal website example: live playground to static export →

Read the component and iframe documentation →

Advanced API: control your own iframe

Use DevJar for managed previews. The advanced useDevJar hook lets you own the iframe and decide when a project runs.

import { useDevJar } from 'devjar'function Preview({ files }) {  const { ref, load, error } = useDevJar({ tailwind: false })  return (    <>      <button onClick={() => void load(files)}>Run</button>      {error != null && <pre>{String(error)}</pre>}      <iframe ref={ref} title="Live preview" />    </>  )}

CLI: build a site without the setup

Requires Node.js 22 or newer. Devjar keeps the project structure simple and handles the production details for you.

Routes from files

Files inside pages/ become routes, including nested pages and a custom 404.

An optional package.json pins dependency versions. Packages load from the CDN, so you don’t need to install them.

package.json          # optional: dependency versionsicon.svg              # shared site iconopengraph-image.jpg    # shared social imagepages/├── index.tsx          → /├── about.tsx          → /about└── docs/    └── start.tsx      → /docs/start

Self-contained production builds

Routes are prerendered to HTML. Dependencies are vendored, and imported assets and Tailwind CSS are emitted with content hashes.

Tailwind CSS

Add tailwindcss or @tailwindcss/browser to enable Tailwind. Use complete class names; builds emit CSS with no runtime compiler.

Tailwind support is limited to utility classes. Tailwind-specific directives in imported CSS, such as @theme, @apply, and @utility, are not supported. Use CSS variables, ordinary classes, and native media queries for custom styles. Import each stylesheet from JS/TS; nested CSS @import rules are not supported in development.

Three commands

Develop locally, create the static output, then preview exactly what you will deploy.

npx devjar devnpx devjar buildnpx devjar start
Detailed CLI reference: sitemap and options

Run npx devjar [command] [root] [options]. The project root defaults to the current directory. Running without arguments shows help.

CommandWhat it does
dev [root]Serve source pages with live updates.
build [root]Export the site to dist/.
start [root]Serve an existing build.

Sitemap

Pass --sitemap to build to write sitemap.xml in the output directory. Set --origin to your public site URL; use --base when deploying under a subdirectory.

npx devjar build --origin https://example.com --sitemapnpx devjar build --origin https://example.com --base /blog/ --sitemap=site-map.xml

The sitemap includes built page routes, excluding 404 and pages omitted with --exclude. The filename must be an .xml file in the output directory root. Without --origin, the build uses the Vercel production URL when available, or http://localhost:3000.

Options

OptionCommandsDefault and purpose
--host <host>dev, startlocalhost; use 0.0.0.0 for network access.
--port <port>, -pdev, start3000; port to listen on.
--cdn <url>dev, buildhttps://esm.sh; ESM module CDN.
--exclude <path>buildOmit a page file or directory; repeat the option for multiple paths.
--mathdev, buildRender LaTeX math in Markdown pages.
--theme <name>dev, buildminimal, github, editorial, or academic; defaults to minimal.
--base <path>dev, build/; public path for subdirectory deployment.
--origin <url>buildAbsolute origin for metadata and sitemap URLs; defaults to the Vercel production URL or http://localhost:3000.
--sitemap[=<filename>]buildWrite a sitemap; default filename sitemap.xml.
-o, --out-dir <directory>build, startdist; output directory inside the project.
-h, --helpallShow help.
-v, --versionallShow the installed version.