@composy/engine-vue
v0.0.1
Published
Vue 3 adapter for LDesign Engine
Maintainers
Readme
@composy/engine-vue
@composy/engine-vue 是 LDesign Engine 的 Vue 3 适配包。它建立在 @composy/engine-core 之上,只处理 Vue 应用挂载、依赖注入、组合式 API、组件和 Vue 生态可选集成。
适配层边界
- 复用 core 的插件、生命周期、状态、事件、中间件、配置、错误处理和性能监控。
- 本包只增加 Vue 相关能力:
createApp()、mount()、unmount()、provide/inject、组件、组合式 API 和 Vue DevTools。 - router/i18n 是可选集成,未安装对应包时不应影响基础引擎能力。
主要能力
createVueEngine()/VueEngine:创建并管理 Vue 应用级引擎。EngineProvider:在组件树中提供引擎上下文。ErrorBoundary:Vue 组件错误边界。useEngine()、useEngineState()、useEngineEvent():访问 core 引擎、状态和事件。useAsyncState()、useComputedState()、useDebouncedState()、usePersistentState():Vue 化状态工具。usePluginApi()、useMiddleware()、usePerformance()、useTimeTravel():复用 core 的运行时能力。createRouterPlugin()、createI18nPlugin():可选生态桥接。createVueDevtoolsAdapter():将 core 状态、事件和时间旅行接入 Vue DevTools。
快速开始
import { createVueEngine } from '@composy/engine-vue'
import App from './App.vue'
const engine = createVueEngine({
name: 'ldesign-vue-app',
debug: import.meta.env.DEV,
app: {
rootComponent: App,
rootProps: {
tenant: 'demo',
},
},
})
await engine.mount('#app')组件内使用:
<script setup lang="ts">
import { useEngine, useEngineState } from '@composy/engine-vue'
const engine = useEngine()
const ready = useEngineState<boolean>('ready', false)
function markReady(): void {
engine.events.emit('app:ready')
ready.value = true
}
</script>
<template>
<button type="button" @click="markReady">
{{ ready ? 'ready' : 'booting' }}
</button>
</template>目录结构
src/
components/ # EngineProvider、ErrorBoundary
composables/ # useEngine/useAsyncState/usePerformance 等
config/ # Vue 应用配置类型与 defineConfig
devtools/ # Vue DevTools 桥接
engine/ # VueEngine
plugins/ # router/i18n 等可选插件
style/ # 组件样式
index.ts # 统一公开入口构建产物
dist/ # UMD/browser 产物、CSS 和 index.min.js
es/ # ESM 主产物、CSS 和 .d.ts
esm/ # 保留模块结构的 ESM/Less 产物
lib/ # CommonJS 产物样式入口:
@composy/engine-vue/index.css@composy/engine-vue/index.min.css
验证命令
pnpm run lint:check
pnpm run type-check
pnpm run test
pnpm run test:performance
pnpm run build从工作区根目录可运行:
pnpm run build:vue
pnpm run playground:dev:vue
pnpm run playground:build:vue
pnpm run outputs:check维护规则
- Vue 层新增能力前,先确认是否能在
@composy/engine-core中实现为框架无关 API。 - Vue composable 只负责把 core 状态和生命周期映射成
ref、computed、watch等 Vue 习惯用法。 - Vue 插件只负责安装到 Vue App 或向 core 插件上下文补充 Vue 信息,不应改变 core 插件协议。
- 测试优先覆盖源码入口,不依赖构建产物。
