/capacitor-frameworks:capacitor-vuefrom capacitor-frameworks
Guides Vue 3 developers through Capacitor app development with Composition API patterns, composables for native features, reactive plugin state, lifecycle hooks, Vue Router deep link integration, platform detection, PWA Elements, Quasar, and Nuxt integration.
Ships in capacitor-frameworks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Vue-specific patterns and best practices for Capacitor app development — Composition API, composables, reactivity, lifecycle hooks, Vue Router integration, and framework-specific guidance for Quasar and Nuxt.
vite.config.ts, vite.config.js, quasar.config.js, quasar.config.ts, nuxt.config.ts, package.json, capacitor.config.ts or capacitor.config.json, and existing directory structure. Only ask the user when something cannot be detected.Auto-detect the following by reading project files:
vue version from package.json.@capacitor/core version from package.json. If not present, Capacitor has not been added yet — proceed to Step 2.quasar.config.js or quasar.config.ts — Quasar project. Proceed to references/quasar.md.nuxt.config.ts or nuxt.config.js — Nuxt project. Proceed to references/nuxt.md.vite.config.ts or vite.config.js — Plain Vue (Vite) project. Continue with the steps below.android/, ios/).capacitor.config.ts (TypeScript) or capacitor.config.json (JSON).build.outDir from vite.config.ts or vite.config.js. The default is dist.Skip if @capacitor/core is already in package.json. Skip if the project uses Quasar (Quasar has its own Capacitor integration — see references/quasar.md).
Install Capacitor core and CLI in version 8:
npm install @capacitor/core@8
npm install -D @capacitor/cli@8
Always name the version 8. Do not use the latest tag and do not leave the version out. Both can install a newer major version than this skill covers.
Initialize Capacitor. Pass the app name, the app ID and the web directory. Without them the CLI asks for them in the terminal. Ask the user for the app name and the app ID (reverse-domain format, e.g. com.example.app):
npx cap init "<appName>" <appId> --web-dir dist
Use the Vue build output path detected in Step 1 as the web directory. For Vite-based Vue projects, this is typically dist.
Verify the webDir value in the generated capacitor.config.ts or capacitor.config.json matches the Vue build output path. If incorrect, update it:
capacitor.config.ts:
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'my-app',
webDir: 'dist',
};
export default config;
capacitor.config.json:
{
"appId": "com.example.app",
"appName": "my-app",
"webDir": "dist"
}
Build the Vue app and add platforms:
npm run build
npm install @capacitor/android@8 @capacitor/ios@8
npx cap add android
npx cap add ios
npx cap sync
A Capacitor Vue project (Vite-based) has this structure:
my-app/
├── android/ # Android native project
├── ios/ # iOS native project
├── public/
├── src/
│ ├── assets/
│ ├── components/
│ ├── composables/ # Custom composables for Capacitor plugins
│ ├── router/
│ │ └── index.ts # Vue Router configuration
│ ├── views/
│ ├── App.vue
│ └── main.ts
├── capacitor.config.ts # or capacitor.config.json
├── index.html
├── package.json
├── tsconfig.json
└── vite.config.ts
Key points:
android/ and ios/ directories contain native projects and should be committed to version control.src/ directory contains the Vue app, which is the web layer of the Capacitor app.src/composables/.src/.Capacitor plugins are plain TypeScript APIs. Import and call them directly in Vue components using the Composition API.
Install an official @capacitor/* plugin in the major version of @capacitor/core of the project, for example npm install @capacitor/geolocation@8 in a Capacitor 8 project. Do not use the latest tag and do not leave the version out. Both can install a plugin for a newer Capacitor major version. Then run npx cap sync.
<script setup lang="ts">
import { ref } from 'vue';
import { Geolocation } from '@capacitor/geolocation';
const latitude = ref<number | null>(null);
const longitude = ref<number | null>(null);
async function getCurrentPosition() {
const position = await Geolocation.getCurrentPosition();
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
}
</script>
<template>
<div>
<p>Latitude: {{ latitude }}</p>
<p>Longitude: {{ longitude }}</p>
<button @click="getCurrentPosition">Get Location</button>
</div>
</template>
Wrapping Capacitor plugins in composables provides reusability, encapsulated reactive state, and automatic cleanup:
// src/composables/useCamera.ts
import { ref } from 'vue';
import { Camera } from '@capacitor/camera';
import type { MediaResult } from '@capacitor/camera';
export function useCamera() {
const photo = ref<MediaResult | null>(null);
const error = ref<string | null>(null);
async function takePhoto(): Promise<void> {
try {
error.value = null;
photo.value = await Camera.takePhoto({ quality: 90 });
} catch (e) {
error.value = e instanceof Error ? e.message : String(e);
}
}
async function pickFromGallery(): Promise<void> {
try {
error.value = null;
const { results } = await Camera.chooseFromGallery({ quality: 90 });
photo.value = results[0] ?? null;
} catch (e) {
error.value = e instanceof Error ? e.message : String(e);
}
}
return {
photo,
error,
takePhoto,
pickFromGallery,
};
}
Camera.takePhoto() and Camera.chooseFromGallery() need @capacitor/camera 8.1.0 or later. This version deprecated Camera.getPhoto() and Camera.pickImages(). If the project has an older version of the plugin, use Camera.getPhoto({ quality: 90, resultType: CameraResultType.Uri, source: CameraSource.Camera }) (or CameraSource.Photos for the gallery) and the type Photo.
Use the composable in a component. The samples import with relative paths. A project from npm create vite has no @/ alias.
<!-- src/components/PhotoCapture.vue -->
<script setup lang="ts">
import { useCamera } from '../composables/useCamera';
const { photo, error, takePhoto } = useCamera();
</script>
<template>
<div>
<button @click="takePhoto">Take Photo</button>
<p v-if="error">Error: {{ error }}</p>
<img v-if="photo?.webPath" :src="photo.webPath" alt="Captured photo" />
</div>
</template>
Capacitor plugin event listeners must be registered in onMounted and removed in onUnmounted to prevent memory leaks. Vue's reactivity system picks up ref changes automatically, so there is no NgZone-equivalent issue — but cleanup is still critical.
// src/composables/useNetwork.ts
import { ref, onMounted, onUnmounted } from 'vue';
import { Network } from '@capacitor/network';
import type { ConnectionStatus } from '@capacitor/network';
import type { PluginListenerHandle } from '@capacitor/core';
export function useNetwork() {
const status = ref<ConnectionStatus | null>(null);
let listenerHandle: PluginListenerHandle | null = null;
onMounted(async () => {
status.value = await Network.getStatus();
listenerHandle = await Network.addListener('networkStatusChange', (newStatus) => {
status.value = newStatus;
});
});
onUnmounted(async () => {
await listenerHandle?.remove();
});
return {
status,
};
}
Usage in a component:
<!-- src/components/NetworkStatus.vue -->
<script setup lang="ts">
import { useNetwork } from '../composables/useNetwork';
const { status } = useNetwork();
</script>
<template>
<p v-if="status">Network: {{ status.connected ? 'Online' : 'Offline' }}</p>
</template>
For listeners that should persist for the entire app lifecycle (e.g., app state changes), register them in App.vue:
<!-- src/App.vue -->
<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue';
import { App } from '@capacitor/app';
import type { PluginListenerHandle } from '@capacitor/core';
import { RouterView } from 'vue-router';
let appStateListener: PluginListenerHandle | null = null;
onMounted(async () => {
appStateListener = await App.addListener('appStateChange', (state) => {
console.log('App state changed. Is active:', state.isActive);
});
});
onUnmounted(async () => {
await appStateListener?.remove();
});
</script>
<template>
<RouterView />
</template>
Use Capacitor.isNativePlatform() and Capacitor.getPlatform() to conditionally run native-only code. Wrap this in a composable for reuse:
// src/composables/usePlatform.ts
import { Capacitor } from '@capacitor/core';
export function usePlatform() {
const platform = Capacitor.getPlatform() as 'web' | 'ios' | 'android';
const isNative = Capacitor.isNativePlatform();
const isIos = platform === 'ios';
const isAndroid = platform === 'android';
const isWeb = platform === 'web';
return {
platform,
isNative,
isIos,
isAndroid,
isWeb,
};
}
Use it in components to show/hide native-only features:
<!-- src/components/DeviceSettings.vue -->
<script setup lang="ts">
import { usePlatform } from '../composables/usePlatform';
const { isNative } = usePlatform();
function openNativeSettings() {
// Native-only logic
}
</script>
<template>
<button v-if="isNative" @click="openNativeSettings()">Open Device Settings</button>
</template>
Handle deep links by mapping Capacitor's App.addListener('appUrlOpen', ...) event to Vue Router navigation. Read references/deep-links-and-back-button.md for the composable useDeepLinks() and call it in src/App.vue.
Handle the Android hardware back button using App.addListener('backButton', ...) combined with Vue Router. Read references/deep-links-and-back-button.md for the composable useBackButton() and call it in src/App.vue.
Check canGoBack before calling App.exitApp().
Some Capacitor plugins (e.g., Camera, Toast) use @ionic/pwa-elements for their UI on the web. With @capacitor/camera 8.1.0 or later, Camera.takePhoto() falls back to a file input when PWA Elements are not installed, and Camera.chooseFromGallery() always uses a file input on the web. If the project uses any of these plugins and targets the web:
Install PWA Elements:
npm install @ionic/pwa-elements
Register the custom elements in src/main.ts before createApp():
import { createApp } from 'vue';
import { defineCustomElements } from '@ionic/pwa-elements/loader';
import App from './App.vue';
import router from './router';
defineCustomElements(window);
const app = createApp(App);
app.use(router);
app.mount('#app');
After making changes to the Vue app, build and sync to native platforms:
npm run build
npx cap sync
To run on a device or emulator, list the targets first and pass one ID. Without --target the CLI asks for a device in the terminal when more than one is available:
npx cap run android --list
npx cap run android --target <android-target-id>
npx cap run ios --list
npx cap run ios --target <ios-target-id>
To open the native IDE for advanced configuration or debugging:
npx cap open android
npx cap open ios
The Capacitor CLI does not start the Vite dev server. Start it first and make it reachable from the network. The command keeps running, so start it in a second terminal or as a background process:
npm run dev -- --host
Vite prints the network URL of the dev server (the default port is 5173). The device must be in the same network as the computer. Then run the app with the host and the port of this URL:
npx cap run android --live-reload --host <ip-address> --port 5173 --target <android-target-id>
npx cap run ios --live-reload --host <ip-address> --port 5173 --target <ios-target-id>
The options --livereload and --external belong to the Ionic CLI (ionic cap run). The Capacitor CLI does not have them.
webDir mismatch: If npx cap sync copies the wrong files, verify that webDir in capacitor.config.ts or capacitor.config.json matches the Vue build output path. For Vite-based Vue projects, the default output directory is dist.npx cap sync after installing any new plugin. Verify the plugin appears in package.json dependencies.onUnmounted. Store the PluginListenerHandle returned by addListener and call handle.remove() on unmount.android/app/src/main/AndroidManifest.xml for Android, ios/App/App/Info.plist and associated domain entitlement for iOS). Verify useDeepLinks() is called in App.vue.canGoBack before calling App.exitApp(). Only exit when there is no navigation history.defineCustomElements(window) is called in src/main.ts before createApp(). Verify @ionic/pwa-elements is installed.npx quasar mode add capacitor instead of manually installing Capacitor. See references/quasar.md.ssr: false in nuxt.config.ts to generate a static SPA. See references/nuxt.md.npx cap run fails with an unknown option --livereload or --external: These are options of the Ionic CLI. Use the commands in the Live Reload section of Step 10.--host, and that the host passed to npx cap run is the network address of the dev server, not localhost.Camera.takePhoto is not a function: The installed @capacitor/camera is older than 8.1.0. In a Capacitor 8 project, update the plugin with npm install @capacitor/camera@8 and run npx cap sync. In a Capacitor 6 or 7 project, use Camera.getPhoto().capacitor-app-creation — Create a new Capacitor app from scratch.capacitor-app-development — General Capacitor development guidance not specific to Vue.capacitor-plugins — Install and configure Capacitor plugins from official and community sources.capacitor-angular: Angular-specific patterns and best practices for Capacitor app development.capacitor-react: React-specific patterns and best practices for Capacitor app development.ionic-vue — Ionic Framework with Vue (UI components, navigation, theming on top of Capacitor).capacitor-app-upgrades — Upgrade a Capacitor app to a newer major version.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub capawesome-team/skills --plugin capacitor-frameworks3 skills in this plugin
/capacitor-angularGuides the agent through Angular-specific patterns for Capacitor app development. Covers project structure, adding Capacitor to Angular projects, using Capacitor plugins in Angular services and components, change detection for plugin event listeners with signals in zoneless and zone-based apps (NgZone integration), lifecycle hook patterns, dependency injection, routing with deep links, live reload, and platform detection. Do not use for creating a new Capacitor app from scratch, upgrading Capacitor versions, installing specific plugins, Ionic Framework setup, or non-Angular frameworks./capacitor-reactGuides the agent through Capacitor app development with React — project structure, hooks for native features, state management patterns, using Capacitor plugins in React components, and React-specific best practices. Do not use for Ionic Framework with React (use ionic-react), migrating or upgrading Capacitor apps or plugins, or non-React frameworks.Other plugins' skills for the same job