๐Ÿ”— 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 server

Dev 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.