๐ Related cheat sheets:
- ๐ง Sveltia CMS: sveltia-cms.md
- ๐งฑ Sveltia + Hugo: sveltia-hugo.md
- ๐ Hugo core: hugo.md
- ๐งพ Hugo Markdown: hugo_markdown.md
- ๐จ Hugo themes & addons: hugo_themes-and-addons.md
Goal: fast local dev and build workflow for /home/dv/sveltia-cms.
โก Quickstart dev loop
From your shell:
cd /home/dv/sveltia-cms
pnpm install # first time only
pnpm dev # start dev serverDev server:
- URL: http://localhost:55151/
- Config: vite.config.js โ server.port = 55151, strictPort = true, host = โ0.0.0.0โ.
Common scripts (package.json):
- pnpm dev โ Vite dev server.
- pnpm build โ library build to package/dist.
- pnpm build:watch โ watch build.
- pnpm test / pnpm test:watch โ vitest test runs.
- pnpm test:coverage โ vitest with coverage.
- pnpm check โ runs all lint/format checks.
๐๏ธ Build pipeline (library mode)
Key pieces (vite.config.js):
- Entry: src/lib/main.js
- Outputs (Rollup):
- sveltia-cms.js (IIFE) โ for
- sveltia-cms.mjs (ES module) โ for import CMS from โ@sveltia/cmsโ.
- outDir: package/dist
Custom Vite plugins:
- copyPackageFiles()
- Reads root package.json.
- Strips dev-only parts (dependencies, scripts).
- Writes a trimmed package/package.json plus LICENSE.txt and README.md.
- generateExtraFiles()
- generateTypes() โ TypeScript declarations into package/.
- generateSchema() โ JSON schema into package/schema/sveltia-cms.json.
Result: pnpm build leaves a publishable package/ folder with:
- dist bundles (JS).
- main.d.ts + types/public.d.ts.
- schema/sveltia-cms.json.
- trimmed package.json, LICENSE, README.
๐งฌ Types and schema internals
Types:
- generateTypes() runs tsc on src/lib/main.js with allowJs and declarations only.
- Writes d.ts files (main.d.ts, types/public.d.ts).
- Appends a named export for CmsConfig.
- Normalizes deprecation markers inside public.d.ts.
Schema:
- generateSchema() uses ts-json-schema-generator on the CmsConfig type.
- Adds:
- Title + description metadata.
- $schema support at top of config files.
- oneOf rule ensuring either collections or singletons is present.
- widget name validation so custom widgets cannot collide with built-ins.
- Writes package/schema/sveltia-cms.json.
- Published at: https://unpkg.com/@sveltia/cms/schema/sveltia-cms.json
Usage in editors:
- In YAML config:
# yaml-language-server: $schema=https://unpkg.com/@sveltia/cms/schema/sveltia-cms.json- In TOML config:
#:schema https://unpkg.com/@sveltia/cms/schema/sveltia-cms.json- In JSON config:
"$schema": "https://unpkg.com/@sveltia/cms/schema/sveltia-cms.json",๐ Project layout (high level)
- src/lib/
- main.js โ library entry point (exports CMS API for embedding).
- components/ โ Svelte UI components for the CMS.
- services/ โ logic for contents, widgets, data output, backends, etc.
- package/
- dist/ โ build artifacts (JS bundles).
- schema/ โ sveltia-cms.json for config validation.
- types/ โ public TypeScript declarations.
- main.d.ts โ main type declarations.
(Exact module names may evolve, but this is the mental map.)
๐ Dev & build gotchas
- Make sure Node version supports Vite 7 and Svelte 5 (current LTS is safe).
- Use pnpm consistently; mixing npm/yarn may leave conflicting lockfiles.
- If port 55151 is busy, Vite will fail (strictPort = true) instead of auto-switching; free the port or stop other dev servers.
- If build fails on types/schema, inspect scripts/generation and ts-json-schema-generator; type errors in CmsConfig ripple into schema generation.
- When publishing, prepublishOnly is wired to vite build; local publish tests should run pnpm build before npm publish / pnpm publish.