快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-live-reload`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/live-reload/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-live-reload` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-live-reloadbunx cap sync导入
“导入”章节import { LiveReload } from '@capgo/capacitor-live-reload';快速入门
章节标题为“快速入门”import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.configureServer({ url: 'https://example.com' });console.log(result);示例:连接
标题为“示例:连接”的章节import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.connect();console.log(result);示例:断开连接
章节标题为“示例:断开连接”import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.disconnect();console.log(result);常见坑点
章节标题为“常见陷阱”- 监听器: 在页面卸载时移除句柄。
- 原生同步:运行
bunx cap sync在插件升级后。 - 唯一可信来源:信任
src/definitions.ts在 GitHub 仓库中。
API 概览
章节标题:“API 概览”configureServer
标题为 “configureServer” 的章节存储远程开发服务器设置,供后续连接使用。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.configureServer({ url: 'https://example.com' });console.log(result);connect
“connect” 章节如果当前没有活跃的 WebSocket 连接,则建立一个新的连接。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.connect();console.log(result);disconnect
“disconnect” 章节关闭当前的 WebSocket 连接并禁用自动重连。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.disconnect();console.log(result);getStatus
标题为“getStatus”的章节返回当前连接状态。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.getStatus();console.log(result);reload
标题为 “reload” 的章节触发 Capacitor WebView 的完整重新加载。
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.reload();reloadFile
标题为“reloadFile”的章节如果运行时支持,则重新加载单个文件/模块(否则回退到完整重新加载)。
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.reloadFile({ path: 'path/to/file' });类型参考
“类型参考” 章节ConfigureServerOptions
标题为“ConfigureServerOptions”的章节export interface ConfigureServerOptions { /** * Base URL for the dev server (e.g. https://dev.local:5173). * When a connection is established the Capacitor WebView navigates to this URL. */ url: string; /** Optional WebSocket path override when different from /ws. */ websocketPath?: string; /** Extra headers sent when creating the WebSocket connection. */ headers?: Record<string, string>; /** Automatically reconnect when the socket closes unexpectedly. Default: true. */ autoReconnect?: boolean; /** Delay (ms) between reconnection attempts. Default: 2000. */ reconnectInterval?: number;}LiveReloadStatus
标题为“LiveReloadStatus”的章节export interface LiveReloadStatus { connected: boolean; url?: string;}FileUpdatePayload
标题为“FileUpdatePayload”的章节export interface FileUpdatePayload { path: string; hash?: string;}LiveReloadEventCallback
标题为“LiveReloadEventCallback”的章节export type LiveReloadEventCallback = (event: LiveReloadEventPayload) => void;LiveReloadStatusCallback
标题为“LiveReloadStatusCallback”的章节export type LiveReloadStatusCallback = (status: LiveReloadStatus) => void;LiveReloadEventPayload
标题为“LiveReloadEventPayload”的章节export interface LiveReloadEventPayload { type: LiveReloadMessageType; /** Populated when type === 'file-update'. */ file?: FileUpdatePayload; /** Optional human-readable message for errors or status changes. */ message?: string;}LiveReloadMessageType
标题为“LiveReloadMessageType”的章节export type LiveReloadMessageType = 'full-reload' | 'file-update' | 'error' | 'connected' | 'disconnected';单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-live-reload 用于“使用 @capgo/capacitor-live-reload”中的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。