cem-serve
Set up cem serve for custom element development. Use when the user asks to "start dev server", "set up cem serve", "preview elements", "run demos", or needs help configuring the dev server, import maps, or CSS transforms.
What this skill does
# Set Up CEM Serve for Development
Configure and run `cem serve` to preview custom elements with live reload,
auto-generated import maps, and interactive knobs.
## Best Practices
### Package Dependencies
Runtime imports must be in `dependencies`, not `devDependencies`. The import
map generator only resolves packages from `dependencies`.
```json
{
"dependencies": {
"lit": "^3.0.0"
},
"devDependencies": {
"@pwrs/cem": "^0.9.0"
}
}
```
### Project Config
Create `.config/cem.yaml` with generate and serve sections:
```yaml
generate:
files:
- elements/*/my-*.ts
output: custom-elements.json
designTokens:
spec: tokens/my-tokens.json
prefix: my-prefix
demoDiscovery:
fileGlob: elements/*/demo/*.html
urlPattern: /elements/:tag/demo/:demo.html
urlTemplate: /elements/{{.tag}}/demo/{{.demo}}/
serve:
transforms:
css:
include:
- "elements/**/*.css"
```
- `generate.files`: globs for element source files
- `generate.output`: manifest output path
- `generate.designTokens`: DTCG token file and CSS custom property prefix
- `generate.demoDiscovery`: how to find and route demo files
- `serve.transforms.css.include`: globs for CSS files to serve as JS modules (enables `import styles from './el.css' with { type: 'css' }`)
### Demo Files
Demos are **HTML partials**, not full documents. No `<!DOCTYPE>`, `<html>`, or
`<head>`. Include inline `<script type="module">` and `<style>` as needed.
The `index.html` demo is the default — keep it minimal (simplest possible usage).
Additional demos show specific features or variants.
Use `<meta itemprop="name">` and `<meta itemprop="description">` on non-index
demos for display in the dev server UI.
For demo authoring conventions, see the `write-demos` skill.
### Testing with Chromeless Mode
`cem serve --rendering=chromeless` strips the dev server UI, serving bare demo
HTML with import maps and transforms — ideal for browser-based testing with
Playwright or Puppeteer. Append `?rendering=chromeless` to any demo URL for
per-request chromeless mode without restarting.
See the `gen-tests` skill for full test scaffolding with page objects against
chromeless demos.
## Workflow
### 1. Generate the Manifest
```bash
cem generate
```
Verify demos appear without warnings. If you see "No URL configured for demo",
check that `demoDiscovery.urlPattern` uses URLPattern syntax (`:param` captures,
not regex).
### 2. Start the Server
```bash
cem serve
```
Default port is 8000. Use `--port <n>` to change.
### 3. Verify
Open `http://localhost:8000`. The UI should show element demos in the sidebar.
Check browser console for import errors — if a bare specifier fails, the
package needs to be in `dependencies`.
## Troubleshooting
### Bare specifier errors
Move the package from `devDependencies` to `dependencies` and reinstall.
### Duplicate demo route warnings
Delete the cached manifest and regenerate: `rm custom-elements.json && cem generate`
### Port in use
`lsof -ti:8000 | xargs kill` or use `--port`.
### Stale manifest on background regen
`cem serve` regenerates the manifest in the background on file changes. If the
background regen produces a smaller/empty manifest, ensure `generate.files` in
the config matches your source globs — the background regen uses the config,
not CLI args.
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.