Framework To Capacitor 标志

Framework To Capacitor

组织
Cap-go
framework-to-capacitor

Guide for integrating modern web frameworks with Capacitor. Covers Next.js static export, React, Vue, Angular, Svelte, and others. Use this skill when converting framework apps to mobile apps with Capacitor.

Add to TypingMind

概览

发布者Cap-go
代码仓库capgo-skills
技能名称framework-to-capacitor
星标数
71
复刻数
4
附带文件
1
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 Cap-go 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Framework To Capacitor AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Cap-go/capgo-skills/tree/main/plugins/capacitor-app-migrations/skills/framework-to-capacitor
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Cap-go/capgo-skills.git /tmp/capgo-skills
mkdir -p .claude/skills
cp -r /tmp/capgo-skills/plugins/capacitor-app-migrations/skills/framework-to-capacitor .claude/skills/framework-to-capacitor
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Framework To Capacitor,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Framework To Capacitor。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Framework To Capacitor 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Framework to Capacitor Integration

Comprehensive guide for integrating web frameworks with Capacitor to build mobile apps.

When to Use This Skill

  • Converting a Next.js app to a mobile app
  • Integrating React, Vue, Angular, or Svelte with Capacitor
  • Configuring static exports for Capacitor
  • Setting up routing for mobile apps
  • Optimizing framework builds for native platforms

Live Project Snapshot

Detected framework and build dependencies: !node -e "const fs=require('fs');if(!fs.existsSync('package.json'))process.exit(0);const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const matchers=['next','react','vue','@angular/core','@sveltejs/kit','@builder.io/qwik','@remix-run/react','solid-js','vite','@capacitor/core','@capacitor/cli'];const out=[];for(const section of ['dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(matchers.includes(name))out.push(section+'.'+name+'='+version)}}for(const [name,cmd] of Object.entries(pkg.scripts||{})){if(['build','export','sync','cap:sync'].includes(name))out.push('scripts.'+name+'='+cmd)}console.log(out.join('\n'))"

Relevant framework and Capacitor config paths: !find . -maxdepth 3 \( -name 'next.config.js' -o -name 'next.config.mjs' -o -name 'vite.config.ts' -o -name 'vite.config.js' -o -name 'angular.json' -o -name 'svelte.config.js' -o -name 'capacitor.config.json' -o -name 'capacitor.config.ts' -o -name 'capacitor.config.js' \)

Framework Support Matrix

FrameworkStatic ExportSSR SupportRecommended Approach
Next.js✅ Yes❌ NoStatic export (output: 'export')
React✅ YesN/ACreate React App or Vite
Vue✅ Yes❌ NoVite or Vue CLI
Angular✅ Yes❌ NoAngular CLI
Svelte✅ Yes❌ NoSvelteKit with adapter-static
Remix✅ Yes❌ NoSPA mode
Solid✅ Yes❌ NoVite
Qwik✅ Yes❌ NoStatic site mode

CRITICAL: Capacitor requires static HTML/CSS/JS files. SSR (Server-Side Rendering) does not work in native apps.


Next.js + Capacitor

Next.js is popular for React apps. Capacitor requires static export.

Step 1: Create or Update next.config.js

For Next.js 13+ (App Router):

javascript
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  images: {
    unoptimized: true, // Required for static export
  },
  trailingSlash: true, // Helps with routing on mobile
};

module.exports = nextConfig;

For Next.js 12 (Pages Router):

javascript
// next.config.js
module.exports = {
  output: 'export',
  images: {
    unoptimized: true,
  },
  trailingSlash: true,
};

Step 2: Build Static Files

bash
npm run build

This creates an out/ directory with static files.

Step 3: Install Capacitor

bash
npm install @capacitor/core @capacitor/cli
npx cap init

Configuration:

  • App name: Your app name
  • App ID: com.company.app
  • Web directory: out (Next.js static export output)

Step 4: Configure Capacitor

Create capacitor.config.ts:

typescript
import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'out', // Next.js static export directory
  server: {
    androidScheme: 'https',
  },
};

export default config;

Step 5: Add Platforms

bash
npm install @capacitor/ios @capacitor/android
npx cap add ios
npx cap add android

Step 6: Build and Sync

bash
# Build Next.js
npm run build

# Sync with native projects
npx cap sync

Step 7: Run on Device

iOS:

bash
npx cap open ios
# Build and run in Xcode

Android:

bash
npx cap open android
# Build and run in Android Studio

Next.js Routing Considerations

Use hash routing for complex apps:

typescript
// next.config.js
const nextConfig = {
  output: 'export',
  basePath: '',
  assetPrefix: '',
};

Or use Next.js's built-in routing (works with trailingSlash: true).

Next.js Image Optimization

next/image doesn't work with static export. Use alternatives:

Option 1: Use standard img tag

jsx
// Instead of next/image
<img src="/images/photo.jpg" alt="Photo" />

Option 2: Use a custom Image component

tsx
// components/CapacitorImage.tsx
import { Capacitor } from '@capacitor/core';

export const CapacitorImage = ({ src, alt, ...props }) => {
  const isNative = Capacitor.isNativePlatform();
  const imageSrc = isNative ? src : src;
  
  return <img src={imageSrc} alt={alt} {...props} />;
};

Next.js API Routes

API routes don't work in static export. Use alternatives:

  1. External API: Call a separate backend
  2. Capacitor plugins: Use native features
  3. Local storage: Use @capacitor/preferences
typescript
import { Preferences } from '@capacitor/preferences';

// Save data
await Preferences.set({
  key: 'user',
  value: JSON.stringify(userData),
});

// Load data
const { value } = await Preferences.get({ key: 'user' });
const userData = JSON.parse(value || '{}');

Next.js Middleware

Middleware doesn't work in static export. Handle logic client-side:

typescript
// In your React components
import { useEffect } from 'react';
import { useRouter } from 'next/router';

export default function ProtectedPage() {
  const router = useRouter();

  useEffect(() => {
    const checkAuth = async () => {
      const { value } = await Preferences.get({ key: 'token' });
      if (!value) {
        router.push('/login');
      }
    };
    checkAuth();
  }, []);

  return <div>Protected content</div>;
}

Complete Next.js + Capacitor Example

package.json:

json
{
  "name": "my-capacitor-app",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "build:mobile": "next build && cap sync",
    "ios": "cap open ios",
    "android": "cap open android"
  },
  "dependencies": {
    "next": "^14.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "@capacitor/core": "^6.0.0",
    "@capacitor/ios": "^6.0.0",
    "@capacitor/android": "^6.0.0",
    "@capacitor/camera": "^6.0.0"
  },
  "devDependencies": {
    "@capacitor/cli": "^6.0.0",
    "typescript": "^5.0.0"
  }
}

React + Capacitor

React works great with Capacitor using Vite or Create React App.

Option 1: Vite (Recommended)

Create new project:

bash
npx create-vite@latest my-app --template react-ts
cd my-app
npm install

Install Capacitor:

bash
npm install @capacitor/core @capacitor/cli
npx cap init

Configure vite.config.ts:

typescript
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  build: {
    outDir: 'dist', // Capacitor webDir
  },
});

capacitor.config.ts:

typescript
import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'dist',
};

export default config;

Add platforms and build:

bash
npm install @capacitor/ios @capacitor/android
npx cap add ios
npx cap add android
npm run build
npx cap sync

Option 2: Create React App

Create new project:

bash
npx create-react-app my-app --template typescript
cd my-app

Install Capacitor:

bash
npm install @capacitor/core @capacitor/cli
npx cap init

capacitor.config.ts:

typescript
const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'build', // CRA outputs to build/
};

Build and sync:

bash
npm run build
npx cap sync

React Router Configuration

Use HashRouter for mobile:

tsx
import { HashRouter as Router, Routes, Route } from 'react-router-dom';

function App() {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
      </Routes>
    </Router>
  );
}

Vue + Capacitor

Vue works seamlessly with Capacitor.

Create Vue + Capacitor Project

Using Vite:

bash
npx create-vite@latest my-app --template vue-ts
cd my-app
npm install

Install Capacitor:

bash
npm install @capacitor/core @capacitor/cli
npx cap init

vite.config.ts:

typescript
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [vue()],
  build: {
    outDir: 'dist',
  },
});

capacitor.config.ts:

typescript
const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'dist',
};

Add platforms:

bash
npm install @capacitor/ios @capacitor/android
npx cap add ios
npx cap add android
npm run build
npx cap sync

Vue Router Configuration

Use hash mode for mobile:

typescript
// router/index.ts
import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: '/', component: Home },
    { path: '/about', component: About },
  ],
});

export default router;

Angular + Capacitor

Angular has excellent Capacitor integration.

Create Angular + Capacitor Project

Create Angular app:

bash
npx @angular/cli new my-app
cd my-app

Install Capacitor:

bash
npm install @capacitor/core @capacitor/cli
npx cap init

capacitor.config.ts:

typescript
const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'dist/my-app/browser', // Angular 17+ output
};

For Angular 16 and below:

typescript
webDir: 'dist/my-app',

Add platforms:

bash
npm install @capacitor/ios @capacitor/android
npx cap add ios
npx cap add android
npm run build
npx cap sync

Angular Router Configuration

HashLocationStrategy for mobile:

typescript
// app.config.ts (Angular 17+)
import { provideRouter, withHashLocation } from '@angular/router';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes, withHashLocation()),
  ],
};

For Angular 16 and below:

typescript
// app.module.ts
import { LocationStrategy, HashLocationStrategy } from '@angular/common';

@NgModule({
  providers: [
    { provide: LocationStrategy, useClass: HashLocationStrategy }
  ],
})
export class AppModule {}

Svelte + Capacitor

Svelte and SvelteKit work great with Capacitor.

SvelteKit + Capacitor

Create SvelteKit app:

bash
npx create-svelte my-app
cd my-app
npm install

Install adapter-static:

bash
npm install -D @sveltejs/adapter-static

Configure svelte.config.js:

javascript
import adapter from '@sveltejs/adapter-static';

const config = {
  kit: {
    adapter: adapter({
      pages: 'build',
      assets: 'build',
      fallback: 'index.html',
    }),
  },
};

export default config;

Install Capacitor:

bash
npm install @capacitor/core @capacitor/cli
npx cap init

capacitor.config.ts:

typescript
const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'build',
};

Build and sync:

bash
npm run build
npx cap sync

Vite + Svelte (Simpler Option)

Create with Vite:

bash
npx create-vite@latest my-app --template svelte-ts
cd my-app
npm install

Install Capacitor:

bash
npm install @capacitor/core @capacitor/cli
npx cap init

capacitor.config.ts:

typescript
const config: CapacitorConfig = {
  appId: 'com.company.app',
  appName: 'My App',
  webDir: 'dist',
};

Common Patterns Across Frameworks

1. Environment Detection

Detect if running in native app:

typescript
import { Capacitor } from '@capacitor/core';

const isNative = Capacitor.isNativePlatform();
const platform = Capacitor.getPlatform(); // 'ios', 'android', or 'web'

if (isNative) {
  // Use native plugins
} else {
  // Use web APIs
}

2. Deep Linking

Handle deep links in your app:

typescript
import { App } from '@capacitor/app';

App.addListener('appUrlOpen', (data) => {
  // Handle deep link
  const slug = data.url.split('.app').pop();
  // Navigate to route
});

3. Live Updates with Capgo

Add live updates to any framework:

bash
npm install @capgo/capacitor-updater
typescript
import { CapacitorUpdater } from '@capgo/capacitor-updater';

// Check for updates
const { id } = await CapacitorUpdater.download({
  url: 'https://api.capgo.app/updates',
});

// Apply update
await CapacitorUpdater.set({ id });

4. Native UI Components

Use Ionic Framework for any framework:

bash
npm install @ionic/core

React:

bash
npm install @ionic/react @ionic/react-router

Vue:

bash
npm install @ionic/vue @ionic/vue-router

Angular:

bash
npm install @ionic/angular

5. Storage

Use Capacitor Preferences for all frameworks:

typescript
import { Preferences } from '@capacitor/preferences';

// Set value
await Preferences.set({ key: 'theme', value: 'dark' });

// Get value
const { value } = await Preferences.get({ key: 'theme' });

// Remove value
await Preferences.remove({ key: 'theme' });

// Clear all
await Preferences.clear();

6. Camera Access

Same API across all frameworks:

typescript
import { Camera, CameraResultType } from '@capacitor/camera';

const photo = await Camera.getPhoto({
  quality: 90,
  allowEditing: true,
  resultType: CameraResultType.Uri,
});

const imageUrl = photo.webPath;

Build Scripts for All Frameworks

Add these to package.json:

json
{
  "scripts": {
    "dev": "vite", // or next dev, ng serve, etc.
    "build": "vite build", // or next build, ng build, etc.
    "build:mobile": "vite build && cap sync",
    "ios": "cap run ios",
    "android": "cap run android",
    "sync": "cap sync"
  }
}

Routing Best Practices

Hash vs. History Mode

Hash mode (recommended for mobile):

  • Works without server configuration
  • URLs look like: #/about
  • No server-side routing needed

History mode (requires server):

  • Clean URLs: /about
  • Requires server fallback to index.html
  • Can have issues on mobile

Recommendation: Use hash mode for Capacitor apps.


Common Issues and Solutions

Issue: Blank Screen on Mobile

Cause: Incorrect webDir or build output.

Solution:

  1. Check build output directory matches webDir in capacitor.config.ts
  2. Rebuild: npm run build
  3. Sync: npx cap sync
  4. Check browser console in device

Issue: Routing Doesn't Work

Cause: Using history mode without proper configuration.

Solution: Switch to hash routing:

  • React: HashRouter
  • Vue: createWebHashHistory()
  • Angular: HashLocationStrategy
  • SvelteKit: Configure fallback

Issue: Environment Variables Not Working

Cause: Build-time variables not being replaced.

Solution: Use framework-specific env variable patterns:

  • Next.js: NEXT_PUBLIC_
  • Vite: VITE_
  • Create React App: REACT_APP_
  • Angular: environment.ts

Issue: API Calls Fail on Device

Cause: CORS or localhost URLs.

Solution:

  1. Use production API URLs
  2. Configure CORS on backend
  3. Use Capacitor HTTP plugin for native requests:
typescript
import { CapacitorHttp } from '@capacitor/core';

const response = await CapacitorHttp.get({
  url: 'https://api.example.com/data',
});

Framework-Specific Plugins

Ionic Framework provides native UI components:

  • @ionic/react - React components
  • @ionic/vue - Vue components
  • @ionic/angular - Angular components

Konsta UI for Tailwind CSS:

  • Works with React, Vue, Svelte
  • iOS and Material Design themes

See ionic-design and konsta-ui skills for details.


Deployment Checklist

  • Configure static export (Next.js: output: 'export')
  • Set correct webDir in capacitor.config.ts
  • Use hash routing for mobile
  • Disable image optimization (Next.js)
  • Remove SSR/API routes dependencies
  • Add native permissions (Info.plist, AndroidManifest.xml)
  • Test on physical devices
  • Configure splash screen and icons
  • Set up live updates with Capgo (optional)
  • Build and test on iOS and Android

Resources


Framework-Specific Guides

For detailed guides on specific frameworks:


Next Steps

  1. Choose your framework and follow the setup above
  2. Configure static export/build
  3. Install and configure Capacitor
  4. Add platforms (iOS/Android)
  5. Build and sync
  6. Test on devices
  7. Add native features with plugins
  8. Set up live updates with Capgo

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Framework To Capacitor AI 技能有什么作用?

Guide for integrating modern web frameworks with Capacitor. Covers Next.js static export, React, Vue, Angular, Svelte, and others. Use this skill when converting framework apps to mobile apps with Capacitor.

为什么在 TypingMind 中使用 Framework To Capacitor?

因为您只需安装一次,就能搭配任何模型使用。Framework To Capacitor 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Framework To Capacitor?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Cap-go/capgo-skills/tree/main/plugins/capacitor-app-migrations/skills/framework-to-capacitor。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Framework To Capacitor?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Framework To Capacitor 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Framework To Capacitor 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Framework To Capacitor AI 技能免费吗?

Cap-go 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇