Lompat ke Konten

Getting Started

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

Jendela terminal
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Kemudian gunakan prompt berikut:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-live-reload` plugin in my project.

Jika Anda lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:

Jendela terminal
bun add @capgo/capacitor-live-reload
bunx cap sync
import { LiveReload } from '@capgo/capacitor-live-reload';

Simpan pengaturan server dev remote yang digunakan untuk koneksi berikutnya.

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

Buat koneksi WebSocket jika tidak ada koneksi aktif.

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

Tutup koneksi WebSocket saat ini dan nonaktifkan auto reconnect.

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

Kembalikan status koneksi saat ini.

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

Aktifkan reload penuh dari Capacitor WebView.

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

Reload file/module tunggal jika runtime mendukung (jatuh kembali ke reload penuh).

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

ConfigureServerOptions

Konfigurasi Opsi Server
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

Salin ke clipboard
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';

Halaman ini dihasilkan dari plugin’s src/definitions.ts. Re-run sync ketika public API berubah di atas.

Jika Anda menggunakan Getting Started untuk merencanakan dashboard dan API operasi, hubungkannya dengan Menggunakan @capgo/capacitor-live-reload untuk kemampuan asli di Menggunakan @capgo/capacitor-live-reload, API Overview untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Pengantar, API Kunci untuk detail implementasi di API Kunci, dan Perangkat untuk detail implementasi di Perangkat.