开始使用
复制一个包含安装步骤和此插件的完整 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
getStatus获取当前连接状态。
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.getStatus();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({} 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
“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上游更改时,请重新同步。