跳过内容

开始使用

终端窗口
bun add @capgo/capacitor-live-reload
bunx cap sync
import { LiveReload } from '@capgo/capacitor-live-reload';

用于后续连接的远程开发服务器设置

import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.configureServer({} as ConfigureServerOptions);

如果没有活动的WebSocket连接,则建立一个WebSocket连接

import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.connect();

关闭当前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;
}
export interface LiveReloadStatus {
connected: boolean;
url?: string;
}
export interface FileUpdatePayload {
path: string;
hash?: string;
}
export type LiveReloadEventCallback = (event: LiveReloadEventPayload) => void;

LiveReloadStatusCallback

“LiveReloadStatusCallback”标题
export type LiveReloadStatusCallback = (status: LiveReloadStatus) => void;
export interface LiveReloadEventPayload {
type: LiveReloadMessageType;
/** Populated when type === 'file-update'. */
file?: FileUpdatePayload;
/** Optional human-readable message for errors or status changes. */
message?: string;
}
export type LiveReloadMessageType = 'full-reload' | 'file-update' | 'error' | 'connected' | 'disconnected';

真实数据来源

标题:真实数据来源

本页面由插件生成 src/definitions.ts当公共API上游更改时,请重新同步。