Guide
How to use Live Reload in Capacitor
Using @capgo/capacitor-live-reload
Capacitor plugin to live reload Capacitor apps from a remote Vite dev server.
Install
bun add @capgo/capacitor-live-reload
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { LiveReload } from '@capgo/capacitor-live-reload';
API at a glance
| Method | Description |
|---|---|
configureServer |
Store remote dev server settings used for subsequent connections. |
connect |
Establish a WebSocket connection if one is not already active. |
disconnect |
Close the current WebSocket connection and disable auto reconnect. |
getStatus |
Returns the current connection status. |
reload |
Trigger a full reload of the Capacitor WebView. |
reloadFile |
Reload a single file/module if the runtime supports it (falls back to full reload). |
Examples
configureServer()
Store remote dev server settings used for subsequent connections.
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.configureServer({ url: 'https://example.com' });
console.log(result);
connect()
Establish a WebSocket connection if one is not already active.
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.connect();
console.log(result);
disconnect()
Close the current WebSocket connection and disable auto reconnect.
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.disconnect();
console.log(result);
getStatus()
Returns the current connection status.
import { LiveReload } from '@capgo/capacitor-live-reload';
const result = await LiveReload.getStatus();
console.log(result);
reload()
Trigger a full reload of the Capacitor WebView.
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.reload();
reloadFile()
Reload a single file/module if the runtime supports it (falls back to full reload).
import { LiveReload } from '@capgo/capacitor-live-reload';
await LiveReload.reloadFile({ path: 'path/to/file' });
Listen to events
addListener returns a handle. Call handle.remove() when the screen unmounts, or LiveReload.removeAllListeners() to clear every listener.
Full reference
Keep going from Using @capgo/capacitor-live-reload
If you are using Using @capgo/capacitor-live-reload to plan native plugin work, connect it with @capgo/capacitor-live-reload for the implementation detail in @capgo/capacitor-live-reload, Getting Started for the implementation detail in Getting Started, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins.