@oas-ui/nuxt
v2.3.1
Published
OAS-UI Nuxt 3 module——SSR(DSD 快照)开箱即用:Vue isCustomElement 配置 + theme CSS 注入 + renderOasToString SSR helper
Downloads
1,685
Maintainers
Readme
@oas-ui/nuxt
中文 | English
OAS-UI 的 Nuxt 3 module —— SSR(DSD 快照)开箱即用。
安装
pnpm add @oas-ui/nuxt @oas-ui/ssr @oas-ui/theme用法
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@oas-ui/nuxt'],
})module 自动完成三件事:
- Vue isCustomElement:
vite:extendConfig钩子把oas-*前缀注册进compilerOptions.isCustomElement(与既有配置合并),Vue 不再把oas-*当组件解析、不再告警 - theme CSS 注入:
@oas-ui/theme自动追加到nuxt.options.css(DSD 快照引用的--oas-*token 全局可用);可用oasUi: { theme: false }关闭或传自定义 CSS 入口 - SSR helper 自动导入:
renderOasToString/useOasRender(来自@oas-ui/nuxt/ssr)免 import 直接调用
// server/api/ssr-demo.ts(renderOasToString 已自动导入)
export default defineEventHandler(async () => {
const button = await renderOasToString('oas-button', { type: 'primary' }, '提交')
const empty = await renderOasToString('oas-empty', { description: '暂无数据' }, '', {
locale: 'zh-CN',
})
return `<div class="ssr-demo">${button}${empty}</div>`
})也可显式导入:
import { renderOasToString } from '@oas-ui/nuxt/ssr'客户端 upgrade:页面按需动态 import @oas-ui/ui(见文档站 SSR 指南「客户端专属」小节)。
进程级副作用声明:
renderOasToString首次调用会装载 happy-dom DOM shim 到globalThis(@oas-ui/ssr的既有行为,详见其声明)。
相关包
| 包 | 作用 |
| --- | --- |
| @oas-ui/ssr | 服务端 DSD 渲染引擎 |
| @oas-ui/theme | 设计 token(CSS 变量) |
中文 | English
@oas-ui/nuxt — the Nuxt 3 module for OAS-UI. SSR (DSD snapshots) works out of the box.
Install
pnpm add @oas-ui/nuxt @oas-ui/ssr @oas-ui/themeUsage
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@oas-ui/nuxt'],
})The module does three things automatically:
- Vue isCustomElement: the
vite:extendConfighook registers theoas-*prefix intocompilerOptions.isCustomElement(merged with existing config), so Vue no longer parsesoas-*as components or warns about them - theme CSS injection:
@oas-ui/themeis appended tonuxt.options.cssautomatically (making--oas-*tokens referenced by DSD snapshots globally available); disable withoasUi: { theme: false }or pass a custom CSS entry - SSR helper auto-import:
renderOasToString/useOasRender(from@oas-ui/nuxt/ssr) are callable without an explicit import
// server/api/ssr-demo.ts(renderOasToString auto-imported)
export default defineEventHandler(async () => {
const button = await renderOasToString('oas-button', { type: 'primary' }, '提交')
const empty = await renderOasToString('oas-empty', { description: '暂无数据' }, '', {
locale: 'zh-CN',
})
return `<div class="ssr-demo">${button}${empty}</div>`
})Or import explicitly:
import { renderOasToString } from '@oas-ui/nuxt/ssr'Client-side upgrade: pages dynamically import('@oas-ui/ui') on demand (see the "Client-only" section of the SSR guide on our docs site).
Process-level side-effect note: the first call to
renderOasToStringmounts a happy-dom DOM shim ontoglobalThis(existing behavior of@oas-ui/ssr; see its declaration).
Related packages
| Package | Purpose |
| --- | --- |
| @oas-ui/ssr | Server-side DSD rendering engine |
| @oas-ui/theme | Design tokens (CSS variables) |
