Installation

Usage Guides

Reference

Commands

Language Server

MCP Server

Static Site Generation

TL;DR: Run cem serve --build to generate a static website from your component demos. The output includes server-rendered HTML with Declarative Shadow DOM, transformed source files, and vendored dependencies – ready to deploy anywhere.

Overview

The --build flag renders all your demo pages into a self-contained static site. Each page goes through the same middleware pipeline as the dev server: TypeScript transformation, CSS module wrapping, import map injection, and Lit SSR for Declarative Shadow DOM.

cem serve --build -o dist/

This produces a directory you can serve with any static file server:

python3 -m http.server -d dist/
# or
npx serve dist/

What gets built

OutputDescription
Demo pagesSSR-rendered HTML with Declarative Shadow DOM for all demos
Index pageListing of all components with navigation
User sourcesTypeScript transformed to JavaScript, CSS wrapped as modules
DependenciesVendored from node_modules/ (or rewritten to CDN URLs)
Import mapEmbedded in each page for bare specifier resolution
Chrome bundleSingle JS file with all dev UI components + Lit hydration
sitemap.xmlLists all built pages
custom-elements.jsonThe generated manifest
Health dataPre-rendered at __cem/api/health as static JSON

Dependency resolution

By default, --build vendors dependencies from node_modules/ into the output directory. Use --import to resolve dependencies from a CDN instead:

# Vendor locally (default)
cem serve --build --import vendor

# Use esm.sh CDN
cem serve --build --import esm

# Use jspm CDN
cem serve --build --import jspm

# Use unpkg CDN
cem serve --build --import unpkg

CDN modes rewrite the import map entries from local paths to CDN URLs and skip copying node_modules/. This produces a smaller output that loads dependencies from the network.

Deploying to a subdirectory

When the static site is hosted under a subdirectory (e.g., https://example.com/docs/components/), use --base-path to prefix all URLs:

cem serve --build -o dist/ --base-path /docs/components/

This rewrites asset links, import maps, navigation hrefs, and dynamic imports so they resolve correctly under the given path.

Example

# Build the kitchen-sink example to /tmp/site
cem serve --build -p examples/kitchen-sink -o /tmp/site

# Serve it locally
python3 -m http.server -d /tmp/site

Comparison with the dev server

Featurecem servecem serve --build
Live reloadYesNo
TypeScript transformOn-demandAt build time
SSR (Declarative Shadow DOM)YesYes
Import mapsInjected per-requestEmbedded in HTML
WebSocket clientActiveStubbed (no-op)
Health APILive endpointPre-rendered JSON
OutputHTTP responsesStatic files on disk