Documentation#
Features#
Everything Devjar can do, with a link to the details.
Live previews#
- DevJar component
Render project files in a managed iframe.
- useDevJar hook
Own the iframe and decide when code runs.
- Scheduling edits
Debounce updates or run on demand.
- Loading and errors
Show preview lifecycle states.
- Reset the runtime
Restart a preview without changing source.
- Hosting previews
Compiler assets, CSP, and Next.js setup.
Static sites#
- File-based routes
Pages, nested routes, and a custom 404.
- Markdown pages
Themed HTML pages with no React runtime.
- Tailwind CSS
Utility classes compiled at build time.
- Imports and assets
JSON, text, CSS, images, and fonts.
- Public files and static APIs
Copy files and serve JSON or text.
- Page metadata
Favicon and link previews on X, Slack, and more.
- Sitemap
Generate sitemap.xml for built pages.
- Base path
Deploy under a subdirectory.
- Exclude pages
Keep development pages out of exports.
- Local packages
Develop a library alongside the site.
- Static output and Vercel
Prerendered, self-contained builds.
- Commands and options
Every CLI command and flag.
Browser-only runtime#
Previews and CLI sites run in the browser. Libraries that need a server are not supported.
Live code APIs#
Add live React previews to an editor, docs page, or playground.
Render a project with DevJar#
Pass your files as strings to files. Devjar runs them in an iframe and updates when they change.
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+. Install with npm install devjar. No special hosting headers needed.
Need an editor? Use the Editor from @sugar-high/react. Update files in its onChange to refresh the preview.
Example: edit in a playground, then export the site →
Full API reference →Advanced API: control your own iframe#
Use useDevJar to render into your own iframe and choose when code 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#
Build a static site with no config. Requires Node.js 22+.
Three commands#
Develop, build, then preview the build.
npx devjar devnpx devjar buildnpx devjar startWhile the server runs, browser errors, rejected promises, console.error calls, and failed loads print in the terminal, so you or an agent can see a broken page without opening developer tools.
Preview a single file#
Open one file without creating pages/, such as a report an agent just wrote.
npx devjar report.html # HTML file and its folder, as-isnpx devjar ./output # folder of HTML filesnpx devjar chart.tsx # React component at /npx devjar notes.md # Markdown page at /HTML is served without a build step, and files next to it keep their relative URLs. A folder without index.html lists its HTML files, newest first. Components and Markdown render like pages, with the same imports and live updates.
Routes from files#
Each file in pages/ becomes a route.
Packages load from a CDN, so there is nothing to install. Pin versions in an optional package.json.
package.json # optional: dependency versionspages/├── index.tsx → /├── about.tsx → /about├── docs/start.tsx → /docs/start└── 404.tsx → unmatched routesFiles and folders starting with _ are not routes. You can still import them.
A [name] segment builds many pages from one file. Export paths() to list them; the component receives each item as params.
// pages/[locale]/[lesson].tsx → /en/intro, /en/examples, /zh/intro, …export function paths() { return ['en', 'zh'].flatMap(locale => ['intro', 'examples'].map(lesson => ({ locale, lesson })), )}export default function Lesson({ params }: { params: { locale: string; lesson: string }}) { return <h1>{params.locale}: {params.lesson}</h1>}// pages/index.tsx: / opens /en/export const defaultParams = { locale: 'en' }paths() is synchronous and runs in Node, so read local JS, TS, or JSON data. Unlisted params are 404s. A directory's index.tsx exports either a component or defaultParams. Catch-all, optional, and Markdown [name] pages are not supported. See the README for redirects and other details.
Markdown pages#
Put .md files in pages/. They build to plain HTML with no JavaScript. Pick a theme with --theme: minimal, github, editorial, or academic. Add --math for LaTeX.
npx devjar dev --theme editorialnpx devjar build --theme editorial --math--theme minimal · Room to breathe. Open the full site ↗
See the Markdown guide for frontmatter, custom styles, and math.
Tailwind CSS#
Add tailwindcss or @tailwindcss/browser to your dependencies. Builds output plain CSS. Write full class names, not ones built from strings.
Only utility classes work. @theme, @apply, and @utility are not supported. For custom styles, use CSS variables and plain classes. Import each stylesheet from JS/TS, not with CSS @import.
Imports and assets#
import settings from '../settings.json'import notes from '../notes.md' with { type: 'text' }import logo from '../assets/logo.svg'import '../styles.css'JSON imports as data. type: 'text' imports as a string. Images, fonts, media, and PDFs import as URLs.
Style the page#
Pages render into <div id="__jar">. The only base style removes the body margin, and any rule in your CSS overrides it.
html, body, #__jar { height: 100%; } /* full-height app */body { margin: 8px; } /* browser default margin */#__jar { display: contents; } /* body layout applies to the page */Public files and static APIs#
public/logo.svg → /logo.svgapi/status.json → /api/status.jsonapi/message.txt → /api/message.txtFiles in public/ are copied as is. api/ serves static JSON or text only.
Page metadata#
Add an icon, a share image, and optional share video or audio to the project root. Devjar adds them to every page. No code needed.
icon.svg # browser tab and bookmark iconopengraph-image.png # link preview imageopengraph-video.mp4 # link preview video (optional)opengraph-audio.mp3 # link preview audio (optional)pages/└── index.tsx| File | Formats | Used for |
|---|---|---|
icon.* | .svg, .png, .ico, .jpg, .jpeg, .gif, .webp | Browser tab icon |
opengraph-image.* | .png, .jpg, .jpeg, .gif, .webp | Image in link previews |
opengraph-video.* | .mp4, .webm | Video in link previews |
opengraph-audio.* | .mp3, .ogg, .wav | Audio in link previews |
Devjar adds these tags to each page:
<link rel="icon" href="/icon.svg" type="image/svg+xml"><meta property="og:image" content="https://example.com/opengraph-image.png"><meta name="twitter:image" content="https://example.com/opengraph-image.png"><meta property="og:video" content="https://example.com/opengraph-video.mp4"><meta property="og:video:type" content="video/mp4"><meta property="og:audio" content="https://example.com/opengraph-audio.mp3"><meta property="og:audio:type" content="audio/mpeg"><meta name="twitter:card" content="summary_large_image">Links then show a large image on X, Slack, Discord, LinkedIn, Facebook, iMessage, WhatsApp, and Telegram. Use a 1200 × 630 image. Support for playing video and audio in previews varies by platform, so keep an opengraph-image as the fallback.
Image, video, and audio links are absolute. Build with --origin set to your site URL so they point to your site. Without it, Devjar uses your Vercel URL or http://localhost:3000.
Set each page’s title and description in the page itself:
export default function Page() { return ( <> <title>My website</title> <meta name="description" content="Notes and projects" /> <meta property="og:title" content="My website" /> <meta property="og:description" content="Notes and projects" /> <h1>Hello</h1> </> )}Include the og: tags. Some platforms, like X, ignore <title>. Markdown pages take their title and description from frontmatter.
Sitemap#
Add --sitemap to build to write sitemap.xml. Set --origin to your site URL.
npx devjar build --origin https://example.com --sitemapnpx devjar build --origin https://example.com --base /blog/ --sitemap=site-map.xmlIt lists every built page except 404 and excluded pages. A custom filename must end in .xml.
Base path#
Use --base to host the site in a subdirectory. Pass it to both dev and build.
npx devjar build --base /preview/npx devjar startExclude pages#
Leave drafts or playgrounds out of the build. They still work in dev. Repeat the flag for more paths.
npx devjar build --exclude pages/playground.tsx --exclude pages/draftsLocal packages#
Point a dependency at a local folder. Devjar compiles it, watches for edits, and bundles it in builds.
{ "dependencies": { "my-library": "file:../my-library" }}Static output for any host#
Every page is prerendered to HTML, with all dependencies included. Deploy dist/ to any static host.
On Vercel, choose the Other preset. Caching is set up for you.
All commands and options#
Usage: npx devjar [command] [root] [options]. root defaults to the current folder. Pass a single .html, .tsx, .jsx, or .md file, or a folder without pages/, to preview it directly.
| Command | What it does |
|---|---|
dev [root] | Serve source pages with live updates. |
build [root] | Export the site to dist/. |
start [root] | Serve an existing build. |
Options#
| Option | Commands | Default and purpose |
|---|---|---|
--host <host> | dev, start | localhost; use 0.0.0.0 for network access. |
--port <port>, -p | dev, start | 3000; port to listen on. Without it, a busy port moves to the next free one. |
--cdn <url> | dev, build | https://esm.sh; ESM module CDN. |
--exclude <path> | build | Leave a page or folder out. Repeatable. |
--math | dev, build | Render LaTeX math in Markdown pages. |
--theme <name> | dev, build | minimal, github, editorial, or academic; defaults to minimal. |
--base <path> | dev, build | /; public path for subdirectory deployment. |
--origin <url> | build | Site URL for share images and the sitemap. Defaults to your Vercel URL or http://localhost:3000. |
--sitemap[=<filename>] | build | Write a sitemap; default filename sitemap.xml. |
-o, --out-dir <directory> | build, start | dist; output directory inside the project. |
-h, --help | all | Show help. |
-v, --version | all | Show the installed version. |