@cwa/nuxt

中文文档
2.0.0-alpha.32发布于 2026/11/01MITTypeScriptES Module构建来源已验证

Components Web Apps Nuxt Module. UI for creating component-driven web apps with the API Components Bundle

原始使用文档
文档目录6 节
  1. CWA Module in Action
  2. Template using this module for front-end and API Components…
  3. Development
  4. Linting
  5. Testing
  6. Test coverage for branch {{ current.branch }}

CWA Nuxt Module

[![codecov](https://codecov.io/github/components-web-app/cwa-nuxt-module/branch/{{ current.branch }}/graph/badge.svg?token=Z6GQJN413O)](https://app.codecov.io/gh/components-web-app/cwa-nuxt-module/tree/{{ current.branch }})

This module is designed to work with the API Component Bundle and will provide a full user-interface and utilities to easily create custom web apps with an advanced in-line content management system

CWA Module in Action

Template using this module for front-end and API Components Bundle for back-end

https://github.com/components-web-app/components-web-app

Development

  • Run pnpm run dev:prepare to generate type stubs.
  • Use pnpm run dev to start playground in development mode.

Linting

  • Run pnpm run lint or pnpm run lint:fix

Testing

The module is tested in four layers. Each feature is proven here, in this module. The template's own e2e suite is for projects built from the template, not for module features.

1. Unit and component tests (Vitest)

  • pnpm run test: a single run. Specs sit next to the code they cover (*.spec.ts).
  • pnpm run test:coverage: the same, with coverage.
  • pnpm run test:watch (or pnpm run test:watch:coverage): watch mode during development.
  • pnpm vitest run --reporter=verbose path/to/file.spec.ts: one file.

2. Build-output guards

pnpm run test:e2e builds the playground and runs pnpm run test:e2e:guards against that build:

  • Bundle budgets: the entry chunk and an anonymous visitor's page preloads hold no admin or on-demand code, and stay within their gzip budgets (test/e2e/entry-bundle-markers.mjs, test/e2e/visitor-page-preloads.mjs). Lower a budget when the bundle shrinks. Never raise it just to pass.
  • Prefetching: admin chunks are never prefetched (test/e2e/prefetch-hints.mjs).
  • Server responses: status codes, page-cache headers on errors, sitemap cache headers, and that the server's API URL is never published to the browser.

pnpm run test:types type-checks the module and the playground. pnpm run test:fresh-install packs the package and installs it into a throwaway app.

3. Admin browser tests: rehearsed against the real API, replayed in CI

The admin features (selecting, adding, ordering, publishing, Clone, Move, the shared-component badge and so on) are tested in a real browser with Playwright Test (test/browser/admin.spec.mjs).

CI never talks to a live API. Each scenario is rehearsed once against a real API, and the rehearsal (every request and response) is committed. CI replays it: the recorded responses play the part of the API, and any request missing from the rehearsal fails the scenario. This tests the module against what the real bundle actually answers, with no Docker or registry in CI.

Replay (what CI runs on the lts leg):

pnpm run dev:build
pnpm run test:browser                        # all scenarios
pnpm run test:browser --grep " 23\. "        # one scenario

Rehearse (record against the real API) whenever a scenario, its seed data or the module's requests change:

  1. Run the template application locally at https://localhost with the API Components Bundle version you are testing against, and an admin/admin user.
  2. pnpm run dev:build
  3. pnpm run test:browser:rehearse (or --grep " 23\. " for one scenario).
  4. Commit the changed files in test/browser/rehearsals/.

Rules:

  • Seed your own data. Each scenario creates the layout, pages, routes and components it needs through the API (test/browser/seed.mjs), and never relies on the template's fixtures.
  • The bundle version is recorded. It goes into every rehearsal file. A feature that needs a newer bundle is rehearsed against that bundle, and the changelog names it as the minimum version.
  • One proxy sees everything. The proxy (test/browser/rehearsal.mjs) sits between the playground and the API, so it sees server-side and browser requests alike. It serves Mercure itself as a silent stream, so recordings are deterministic.
  • Defaults: the template's Caddy root CA and the bundle version are read from the components-web-app-php-1 container. Override them with REHEARSAL_CA, REHEARSAL_BUNDLE, REHEARSAL_PHP_CONTAINER or REHEARSAL_API.
  • No sleeps. A console error or page error fails a scenario unless the scenario allows it. Wait for a positive signal, never a fixed delay.
  • The recorder is tested too. test/browser/rehearsal.spec.ts (part of pnpm run test) records against a fake API and replays with it stopped. It covers: the answer after a write, unrecorded requests failing, the path fallback, origin and Mercure rewriting, cookie redaction, and CORS.

4. Before you push

pnpm run lint:fix, pnpm run test, and pnpm run dev:build && pnpm run test:e2e:guards && pnpm run test:browser.

Test coverage for branch {{ current.branch }}

![Codecov sunburst image](https://codecov.io/github/components-web-app/cwa-nuxt-module/branch/{{ current.branch }}/graphs/sunburst.svg?token=Z6GQJN413O)

版本与发布记录

@cwa/nuxt 共发布 32 个版本,首次发布于 2026/09/25;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0-alpha.32latest2026/11/012 天前
2.0.0-alpha.312026/10/303 天前
2.0.0-alpha.302026/10/2311 天前
2.0.0-alpha.292026/10/2311 天前
2.0.0-alpha.282026/10/2311 天前
2.0.0-alpha.272026/10/2212 天前

关于 @cwa/nuxt 的常见问题

@cwa/nuxt 是什么?

组件Web应用下一个模块。用于使用API Components Bundle创建组件驱动的web应用程序的UI

如何安装 @cwa/nuxt?

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

@cwa/nuxt 支持 TypeScript 吗?

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

@cwa/nuxt 支持 ESM 还是 CommonJS?

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

@cwa/nuxt 可以商用吗?

@cwa/nuxt 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cwa/nuxt 还在维护吗?

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