@bettercms-ai/preview-runtime

中文文档
1.0.0发布于 2026/11/05TypeScriptES Module近 30 天下载 1976

Zero-config BetterCMS component previews: builds a preview runtime for Next.js and Astro apps and validates components in CI.

原始使用文档
文档目录6 节
  1. What it needs to know
  2. Commands
  3. Sections extracted from pages
  4. Components with no file
  5. Batch validation
  6. How a preview renders

@bettercms-ai/preview-runtime

Zero-config component previews for Next.js and Astro apps on BetterCMS.

You do not install or configure this package. BetterCMS runs it for you:

  • In your repository's CI. When someone opens Output on a component in the BetterCMS dashboard, BetterCMS adds .github/workflows/bcms-component-validation.yml to your repository (once) and starts it. The workflow runs npx @bettercms-ai/preview-runtime validate, which builds a preview of your app as it is, renders the component in a real browser at each viewport, checks it, and reports the result.
  • On BetterCMS hosting. The preview built in CI is what the dashboard shows, rendered by your own code with live content.

Nothing is written to your repository except that one workflow file. Routes are generated into the CI checkout for the build and removed afterwards.

What it needs to know

Which file implements a component. The agent that writes a component records it through the BetterCMS MCP tool set_component_source (for example src/components/sections/Hero.astro, or components/Hero.tsx with an export name).

Commands

# Build a preview runtime from an app (used by `validate`; useful when debugging locally)
bcms-preview build --manifest manifest.json --out .bcms-preview-release [--cwd path/to/app]

# Validate one component (CI only; configured by BCMS_* environment variables the workflow sets)
bcms-preview validate

manifest.json:

{ "components": [{ "id": "cmp_1", "source": { "path": "src/components/Hero.astro" } }] }

Sections extracted from pages

A component does not have to be a standalone file with its fields as props. A section npx @bettercms-ai/convert --componentize extracted from a page (a file starting // @bettercms-ai/convert section v…) is recognised by that marker and rendered with its section contract: <Section blockId="bcms-preview" overrides={props} page={{}} />, so the live props arrive as the instance's own copy.

Components with no file

A component placed on a page, or used in the project Layout (navigation, footer), needs no recorded file. The manifest lists it as kind: "page"; the preview renders that real route of your app — its loops, child components, collections and page styles exactly as deployed — keeps only the component's own element (data-bcms-block, else the element holding its fields, else the layout's <header>/<footer>), and writes the live props onto it through the same data-bcms-field / data-bcms-layout-field / data-bcms-props attributes the site already declares. A recorded file still wins when there is one.

v1 limits: scripts inside the kept element do not run, so a client island renders its server HTML without hydrating (validation is unaffected). The Next.js page path (render → render-page) is untested against a real Next app yet; Astro is verified.

A failed validation reports what broke — the app server's own error lines first — and the dashboard shows it under "Runtime + console".

Batch validation

One run can validate several components against a single build. When the dispatch carries a batch (BCMS_BATCH, a JSON array of { requestId, componentId, familyKey, nativeViewports }), the validator builds and uploads the runtime once, starts one browser, and validates each component in turn — a component that cannot be validated is reported for that component and the rest carry on. Without BCMS_BATCH it validates the single component named by BCMS_REQUEST_ID / BCMS_COMPONENT_ID / BCMS_FAMILY_KEY / BCMS_NATIVE_VIEWPORTS, as before. The step fails when any component could not be validated.

How a preview renders

  • Astro: built with output: "server" and @astrojs/node, so .astro components render on the server with the props the dashboard sends.
  • Next.js: built with output: "standalone", so client components and async server components render the way they do in your app.

The preview is served under /__bettercms/component-preview/ and only accepts a short-lived, signed session from the BetterCMS dashboard.

版本与发布记录

@bettercms-ai/preview-runtime 共发布 23 个版本,首次发布于 2026/09/13;过去 12 个月发布了 23 个版本。

版本发布日期距今
1.0.0latest2026/11/052 天前
0.13.02026/10/2910 天前
0.12.12026/10/2514 天前
0.12.02026/10/2414 天前
0.11.12026/10/2415 天前
0.11.02026/10/2415 天前

关于 @bettercms-ai/preview-runtime 的常见问题

@bettercms-ai/preview-runtime 是什么?

Zero-config BetterCMS component previews: builds a preview runtime for Next.js and Astro apps and validates components in CI.

如何安装 @bettercms-ai/preview-runtime?

在项目目录运行 npm install @bettercms-ai/preview-runtime,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 bcms-preview,可以用 npx bcms-preview 直接运行。

@bettercms-ai/preview-runtime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bettercms-ai/preview-runtime 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bettercms-ai/preview-runtime 可以商用吗?

@bettercms-ai/preview-runtime 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@bettercms-ai/preview-runtime 的下载量有多少?

根据 npm 官方下载统计,@bettercms-ai/preview-runtime 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,976 次,日均约 66 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bettercms-ai/preview-runtime 还在维护吗?

最新版本 1.0.0 发布于 2026/11/05(2 天前);至今共发布 23 个版本,其中过去 12 个月发布了 23 个;首次发布于 2026/09/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。