Getting Started
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
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.
安装
标题:安装bun add @capgo/capacitor-live-reloadbunx cap sync导入
标题:导入import { LiveReload } from '@capgo/capacitor-live-reload';API 概述
标题:API 概述configureServer
配置服务器用于后续连接的远程开发服务器设置
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.configureServer({} as ConfigureServerOptions);connect
连接如果没有活动的 WebSocket 连接,则建立一个 WebSocket 连接
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.connect();disconnect
断开当前 WebSocket 连接并禁用自动重连复制到剪贴板
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.disconnect();getStatus
复制到剪贴板复制到剪贴板
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.getStatus();reload
重新加载触发 Capacitor WebView 的全局重新加载。
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.reload();reloadFile
重新加载文件如果运行时支持,可以重新加载单个文件/模块(否则会进行全局重新加载)。
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.reloadFile({} as FileUpdatePayload);类型参考
类型参考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
实时重新加载状态export interface LiveReloadStatus { connected: boolean; url?: string;}FileUpdatePayload
文件更新载荷export interface FileUpdatePayload { path: string; hash?: string;}LiveReloadEventCallback
实时重载事件回调export type LiveReloadEventCallback = (event: LiveReloadEventPayload) => void;LiveReloadStatusCallback
实时重载状态回调export type LiveReloadStatusCallback = (status: LiveReloadStatus) => void;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
实时重载消息类型export type LiveReloadMessageType = 'full-reload' | 'file-update' | 'error' | 'connected' | 'disconnected';真实来源
真实来源本页面由插件生成 src/definitions.ts. 当上游的公共 API 变更时,请重新同步
继续从 Getting Started
标题为“继续从 Getting Started”如果您正在使用 Getting Started 来规划仪表板和 API 操作,请将其连接到 使用 @capgo/capacitor-live-reload 用于在 Using @capgo/capacitor-live-reload 中实现的本机功能 API Overview 用于在 API Overview 中实现的详细信息 介绍 在介绍中实现细节 API 键 在 API 键中实现细节 设备 在设备中实现细节