开始使用
复制一个设置提示,包含安装步骤和该插件的完整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.
安装
标题为“安装”您可以使用我们的AI辅助设置来安装插件。将Capgo技能添加到您的AI工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
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';API概述
导入部分:API概述configureServer
配置服务器用于后续连接的远程开发服务器设置
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.configureServer({ url: 'https://example.com' });console.log(result);connect
标题:连接如果没有激活的 WebSocket 连接,则建立一个 WebSocket 连接。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.connect();console.log(result);disconnect
标题:断开连接关闭当前的 WebSocket 连接并禁用自动重连。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.disconnect();console.log(result);getStatus
标题:获取状态返回当前连接状态。
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.getStatus();console.log(result);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
LiveReloadEventCallbackexport type LiveReloadEventCallback = (event: LiveReloadEventPayload) => void;LiveReloadStatusCallback
LiveReloadStatusCallbackexport type LiveReloadStatusCallback = (status: LiveReloadStatus) => void;LiveReloadEventPayload
LiveReloadEventPayloadexport interface LiveReloadEventPayload { type: LiveReloadMessageType; /** Populated when type === 'file-update'. */ file?: FileUpdatePayload; /** Optional human-readable message for errors or status changes. */ message?: string;}LiveReloadMessageType
LiveReloadMessageTypeexport type LiveReloadMessageType = 'full-reload' | 'file-update' | 'error' | 'connected' | 'disconnected';真实数据来源
真实数据来源本页面由插件生成 src/definitions.ts重新同步公共API时,重新运行上游的API
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 开始使用 规划仪表板和 API 操作,连接它与 使用 @capgo/capacitor-live-reload 为使用 @capgo/capacitor-live-reload 的原生能力 API 概述 为 API 概述 的实现细节 介绍 为介绍 的实现细节 API 密钥 为API中的实现细节提供。 设备 Live Update