mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
- Add LoraManagerDemoNode to node mappings for Vue widget demonstration - Update .gitignore to exclude Vue widget development artifacts (node_modules, .vite, dist) - Implement automatic Vue widget build check in development mode with fallback handling - Maintain pytest compatibility with proper import error handling
8.9 KiB
8.9 KiB
Vue Widget 构建流程实施方案
已实施方案:方案1 + 方案4 组合
我们采用了提交构建产物 + 智能检测的混合方案,同时满足用户便利性和开发灵活性。
🎯 方案特点
对于用户
✅ 安装即用 - Clone仓库后无需任何构建步骤 ✅ 无需Node.js - 构建产物已包含在仓库中 ✅ 快速启动 - ComfyUI启动时无延迟
对于开发者
✅ 自动检测 - 源代码变更后自动检测是否需要重新构建 ✅ 自动构建 - 如果检测到需要,可自动执行构建(需要Node.js) ✅ 灵活配置 - 可选择手动或自动构建模式
📦 实施的组件
1. Git 配置调整
文件: .gitignore
- # Vue widgets build output
- web/comfyui/vue-widgets/
+ # Vue widgets development cache (but keep build output)
+ vue-widgets/node_modules/
+ vue-widgets/.vite/
+ vue-widgets/dist/
说明:
- ✅ 构建产物
web/comfyui/vue-widgets/提交到Git - ✅ 开发缓存(node_modules等)被忽略
- ✅ 仓库大小增加约 1.4MB(可接受)
2. 智能构建检测模块
文件: py/vue_widget_builder.py
核心功能:
- ✅ 检查构建产物是否存在
- ✅ 检查源代码是否比构建新(开发模式)
- ✅ 检查Node.js/npm是否可用
- ✅ 自动执行构建(如果需要且可行)
- ✅ 友好的错误提示和日志
主要类和方法:
class VueWidgetBuilder:
def check_build_exists() -> bool
"""检查构建产物是否存在"""
def check_build_outdated() -> bool
"""检查源代码是否比构建新"""
def check_node_available() -> bool
"""检查Node.js是否可用"""
def build_widgets(force=False) -> bool
"""执行构建"""
def ensure_built(auto_build=True, warn_only=True) -> bool
"""确保构建存在,智能处理"""
便捷函数:
check_and_build_vue_widgets(auto_build=True, warn_only=True, force=False)
3. 启动时自动检测
文件: __init__.py
在ComfyUI加载插件时自动检测并构建:
# Check and build Vue widgets if needed (development mode)
try:
from .py.vue_widget_builder import check_and_build_vue_widgets
# Auto-build in development, warn only if fails
check_and_build_vue_widgets(auto_build=True, warn_only=True)
except Exception as e:
logging.warning(f"[LoRA Manager] Vue widget build check skipped: {e}")
行为:
- ✅ 如果构建产物存在且最新 → 静默通过
- ✅ 如果构建产物缺失/过期 → 尝试自动构建(需Node.js)
- ✅ 如果构建失败 → 警告但不阻止ComfyUI启动
- ✅ 开发模式下源代码变更后自动重建
4. 增强的构建脚本
文件: vue-widgets/package.json
{
"scripts": {
"dev": "vite build --watch",
"build": "vite build",
"build:production": "vite build --mode production",
"typecheck": "vue-tsc --noEmit",
"clean": "rm -rf ../web/comfyui/vue-widgets",
"rebuild": "npm run clean && npm run build",
"prepare": "npm run build"
}
}
新增脚本:
clean- 清理构建产物rebuild- 完全重建build:production- 生产模式构建prepare- npm install后自动构建(可选)
5. Pre-commit Hook 示例
文件: vue-widgets/pre-commit.example
提供了Git pre-commit hook示例,确保提交前构建:
#!/bin/sh
cd vue-widgets && npm run build && git add web/comfyui/vue-widgets/
使用方法:
# 手动安装(简单方法)
cp vue-widgets/pre-commit.example .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
# 或使用Husky(推荐用于团队)
npm install --save-dev husky
npx husky install
npx husky add .git/hooks/pre-commit "cd vue-widgets && npm run build"
🔄 工作流程
场景A: 用户安装
# 1. 用户clone仓库
git clone <repo-url>
cd ComfyUI-Lora-Manager
# 2. 启动ComfyUI(无需任何构建步骤)
# 构建产物已在仓库中,直接可用
结果: ✅ 即装即用,无需Node.js
场景B: 开发者修改Vue代码
方式1: 手动构建
cd vue-widgets
npm run build
# 修改会被检测到,ComfyUI重启时会看到最新版本
方式2: 监听模式
cd vue-widgets
npm run dev # Watch mode,自动重建
# 浏览器刷新即可看到变化
方式3: 自动检测
# 修改Vue源代码
vim vue-widgets/src/components/DemoWidget.vue
# 重启ComfyUI
# __init__.py会检测到源代码比构建新,自动重建(如果有Node.js)
场景C: 提交代码
如果安装了pre-commit hook:
git commit -m "Update widget"
# Hook自动执行构建
# 构建产物自动添加到commit
如果没有hook(手动):
cd vue-widgets && npm run build && cd ..
git add .
git commit -m "Update widget and build output"
场景D: CI/CD 发布
# 在GitHub Actions或其他CI中
cd vue-widgets
npm install
npm run build
# 构建产物自动包含在release中
📊 测试结果
已测试以下场景,全部通过:
✅ Test 1: 构建产物存在时
Result: True (静默通过,无日志)
✅ Test 2: 构建产物缺失时
自动检测 → 自动npm install → 自动build → 成功
Result: True
Build created: web/comfyui/vue-widgets/demo-widget.js (418K)
✅ Test 3: 源代码变更检测
修改.vue文件 → 时间戳检测 → 自动重建
Result: True
📁 Git 仓库状态
应该提交的文件:
✅ vue-widgets/src/**/*.{ts,vue} # 源代码
✅ vue-widgets/package.json # 依赖配置
✅ vue-widgets/package-lock.json # 锁定版本
✅ vue-widgets/vite.config.mts # 构建配置
✅ vue-widgets/tsconfig.json # TS配置
✅ vue-widgets/*.md # 文档
✅ web/comfyui/vue-widgets/**/*.js # 构建产物 ⭐
✅ web/comfyui/vue-widgets/**/*.css # 构建CSS ⭐
✅ web/comfyui/vue-widgets/**/*.map # Source maps ⭐
✅ py/vue_widget_builder.py # 构建检测模块 ⭐
应该忽略的文件:
❌ vue-widgets/node_modules/ # npm依赖
❌ vue-widgets/.vite/ # Vite缓存
❌ vue-widgets/dist/ # Vite临时目录
🎓 开发者指南
首次设置
cd vue-widgets
npm install
npm run build
日常开发
# 开发模式(推荐)
cd vue-widgets
npm run dev
# 在另一个终端启动ComfyUI,修改后刷新浏览器
# 或者依赖自动检测
# 修改代码 → 重启ComfyUI → 自动重建
提交前
# 确保构建最新
cd vue-widgets && npm run build && cd ..
# 或者安装pre-commit hook自动化
cp vue-widgets/pre-commit.example .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
🔧 故障排除
问题1: 构建产物不是最新的
症状: 修改了Vue代码,但ComfyUI中看不到变化
解决方案:
cd vue-widgets
npm run rebuild # 强制重建
# 然后刷新浏览器
问题2: 自动构建失败
症状: ComfyUI启动时显示构建失败警告
检查:
# 检查Node.js是否安装
node --version
npm --version
# 手动测试构建
cd vue-widgets
npm install
npm run build
问题3: Git显示大量构建产物变更
这是正常的 - 构建产物应该提交
最小化变更:
- 使用
npm run build而非npm run dev(watch模式) - 确保vite配置中
minify: false(已配置) - 只在需要时重新构建
📈 优势总结
| 方面 | 优势 |
|---|---|
| 用户体验 | ⭐⭐⭐⭐⭐ 安装即用 |
| 开发体验 | ⭐⭐⭐⭐⭐ 自动检测+构建 |
| 可靠性 | ⭐⭐⭐⭐⭐ 构建产物已验证 |
| 灵活性 | ⭐⭐⭐⭐ 支持多种工作流 |
| 维护性 | ⭐⭐⭐⭐ 清晰的构建流程 |
| Git仓库 | ⭐⭐⭐ 略大但可接受 |
🚀 未来优化(可选)
- 添加Husky - 自动化pre-commit hooks
- GitHub Actions - CI自动构建和测试
- 构建缓存 - 加速CI构建
- Minification - 生产模式压缩代码(减小体积)
- 代码分割 - 按需加载不同widget
总结
当前实施的方案完美平衡了用户便利性和开发灵活性:
- ✅ 用户: Clone后即用,无需Node.js
- ✅ 开发者: 自动检测和构建,开发流畅
- ✅ 可靠性: 构建产物已验证提交
- ✅ 可维护性: 清晰的构建流程和文档
用户安装时,web/comfyui/vue-widgets/中的JS代码始终是由vue-widgets中的最新代码编译得到的,因为:
- 开发者提交前会构建(手动或通过hook)
- ComfyUI启动时会检测并自动重建(开发模式)
- 构建产物已包含在Git仓库中(用户直接获得)
这个方案已经过测试验证,可以投入生产使用。