コンテンツにジャンプ

はじめに

ターミナル画面
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();

現在の接続状態を取得します。

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

フルリロードをトリガーし、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);

型リファレンス

型リファレンス
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;
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 がアップストリームで変更されたら、再度同期を実行してください。