Skip to main content
Browse the docs

The developer docs are currently available in Chinese only. The SDK, the CLI and every code sample work the same in any language.

Chapter 11

调试与开发者模式

加载开发中的插件、热重载、看日志

  1. npm run dev(uniflow-plugin dev):监视 src/、panel/、locales/、plugin.json,每次保存重新构建到 dist/。
  2. UniFlow:侧边栏 插件 › 开发者 › 加载开发中的插件…,选 dist/(选项目根目录也行,会自动用里面的 dist/)。
  3. 之后每次重新构建,应用自动重载这个插件(命令重新注册、面板刷新);也可以点卡片上的「重新加载」。
  • 开发中的插件标着「开发中」,优先级最高:与已安装的同 id 插件同时存在时用开发中的版本(插件库「详情」里能看到被顶替的版本)。
  • 加载失败(manifest 不合法、声明了没实现的命令)会直接显示在插件卡片上。
  • 看日志:开发版 UniFlow 打开开发者工具(Console)。面板的 console.log 在面板 iframe 的上下文里;命令代码的日志在 名为 plugin-sandbox-<id> 的 iframe 里的 Worker 上下文里(DevTools 顶部的上下文下拉框切换)。
  • 插件连续崩溃(5 分钟内 3 次:超时、脚本错误)会被停用到下次启动,错误原因会报给调用方。
  • 常见错误:
    • The plugin does not match its manifest —— plugin.json 与 definePlugin 的命令不一致,重新 build;
    • This plugin action has already finished —— 在调用结束后还在用 ctx(定时器、没 await 的 Promise);
    • The plugin returned a value that cannot be sent to the app —— 返回值里有函数 / 类实例 / Map;
    • Unknown parameter args.x —— 参数没在 schema 里声明(additionalProperties: false)。