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 startRoutes 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.
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 --mathTailwind 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.
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 and a share image to the project root. Devjar adds them to every page. No code needed.
icon.svg # browser tab and bookmark iconopengraph-image.png # link preview imagepages/└── 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 |
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 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.
Build with --origin set to your site URL, so image links are absolute. 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.
| 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. |
--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. |