capacitor
БесплатноБез исполняемых скриптовНе проверенCapacitor is a runtime that packages a web app as a native iOS and Android app and exposes native device APIs to JavaScript. Use when someone asks to "convert…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Capacitor
Overview
Capacitor wraps your web app in a native container and gives it access to native device APIs — camera, file system, push notifications, biometrics, geolocation, and more. Your existing React/Vue/Angular/Svelte app becomes an iOS and Android app without rewriting in Swift or Kotlin. Built by the Ionic team, it's the modern replacement for Cordova/PhoneGap. This skill targets Capacitor 8 (iOS 15+, Android 7 / API 24+).
When to Use
- Have a web app and want native iOS/Android versions
- Need native device features (camera, push notifications, biometrics)
- Want one codebase for web + iOS + Android
- Converting a PWA to a native app for App Store distribution
- Team knows web tech but not Swift/Kotlin
Instructions
Setup
The web project needs a package.json and a build output directory (dist, build, www) whose index.html has a <head> tag.
npm install @capacitor/core
npm install -D @capacitor/cli
npx cap init "Trailhead" dev.fernhill.trailhead --web-dir dist
# Add platforms
npm install @capacitor/ios @capacitor/android
npx cap add ios # Swift Package Manager project (default since Capacitor 8)
npx cap add android
cap init writes capacitor.config.ts (or .json when TypeScript is not installed) with the first three keys; plugin settings are added by hand. With TypeScript 7 the CLI loads the .ts config through Node's ES-module loader, so package.json needs "type": "module" (Vite templates have it); without it every cap command stops with Parsing capacitor.config.ts failed:
// capacitor.config.ts
import type { CapacitorConfig } from "@capacitor/cli";
const config: CapacitorConfig = {
appId: "dev.fernhill.trailhead",
appName: "Trailhead",
webDir: "dist",
plugins: {
PushNotifications: { presentationOptions: ["badge", "sound", "alert"] },
},
};
export default config;
Build and Run
# Build your web app first
npm run build
# Copy web assets to native projects and update native dependencies
npx cap sync
# Open in native IDE
npx cap open ios # Opens Xcode
npx cap open android # Opens Android Studio
# Or run directly (run = sync + build + deploy)
npx cap run ios --list # available simulators and devices
npx cap run ios --target-name "iPhone 17" # or --target with an id from --list
npx cap run android
# Live reload from a running dev server (e.g. Vite on port 5173)
npx cap run android --live-reload --port 5173
# Signed release build from the terminal
npx cap build android --androidreleasetype AAB \
--keystorepath release.keystore --keystorepass "$ANDROID_KEYSTORE_PASSWORD" \
--keystorealias upload --keystorealiaspass "$ANDROID_KEY_PASSWORD"
Native Plugins
# Install plugins
npm install @capacitor/camera @capacitor/filesystem @capacitor/push-notifications
npm install @capacitor/haptics @capacitor/share @capacitor/browser
npx cap sync
// src/native/camera.ts — Access the device camera (@capacitor/camera 8.1+)
import { Camera, CameraDirection, MediaTypeSelection } from "@capacitor/camera";
export async function takePhoto(): Promise<string | undefined> {
const photo = await Camera.takePhoto({
quality: 80,
cameraDirection: CameraDirection.Rear,
saveToGallery: false,
});
return photo.webPath; // Path to display in an <img> element
}
export async function pickFromGallery(): Promise<string[]> {
const { results } = await Camera.chooseFromGallery({
mediaType: MediaTypeSelection.Photo,
allowMultipleSelection: true,
limit: 5,
});
return results.flatMap((item) => (item.webPath ? [item.webPath] : []));
}
Camera.getPhoto() and Camera.pickImages() still work but are deprecated since plugin version 8.1; new code should use takePhoto and chooseFromGallery.
// src/native/notifications.ts — Push notifications (iOS and Android only)
import { PushNotifications } from "@capacitor/push-notifications";
export async function registerPush(sendTokenToServer: (token: string) => Promise<void>) {
// Attach listeners before register() so the first event is not missed
await PushNotifications.addListener("registration", (token) => {
void sendTokenToServer(token.value); // FCM token on Android, APNs token on iOS
});
await PushNotifications.addListener("registrationError", (err) => {
console.error("Push registration failed:", err.error);
});
await PushNotifications.addListener("pushNotificationReceived", (notification) => {
console.log("Received:", notification.title, notification.body);
});
let status = await PushNotifications.checkPermissions();
if (status.receive === "prompt") status = await PushNotifications.requestPermissions();
if (status.receive !== "granted") throw new Error("Push permission denied");
await PushNotifications.register();
}
// src/native/filesystem.ts — File system access
import { Directory, Encoding, Filesys
Установить capacitor в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл capacitor?
Capacitor is a runtime that packages a web app as a native iOS and Android app and exposes native device APIs to JavaScript. Use when someone asks to "convert my website to a mobile app", "Capacitor", "web to native app", "access camera from JavaScript", "deploy web app to App Store", "hybrid mobile app", or "Ionic Capacitor". Covers native API access, plugin system, web-to-native bridge, and app store deployment.
Как установить скилл capacitor?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл capacitor запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic