Convert Figma logo to code with AI

ionic-team logocapacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️

11,766
992
11,766
222

Top Related Projects

113,668

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

A framework for building native applications using React

⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.

8,578

Remote Administration Tool for Windows

83,441

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

Quick Overview

Capacitor is an open-source cross-platform app runtime that allows developers to build web apps that run natively on iOS, Android, and the web. It provides a consistent, web-focused set of APIs that enable an app to stay as close to web-standards as possible while accessing rich native device features.

Pros

  • Seamless integration with any web framework or no framework at all
  • Access to native APIs and device features through a unified JavaScript API
  • Easy to add to existing web projects with minimal configuration
  • Active community and regular updates from the Ionic team

Cons

  • Learning curve for developers new to hybrid app development
  • Some advanced native features may require custom plugins or native code
  • Performance may not match fully native apps for highly complex applications
  • Limited IDE support compared to native development environments

Code Examples

  1. Accessing the device's camera:
import { Plugins } from '@capacitor/core';
const { Camera } = Plugins;

async function takePicture() {
  const image = await Camera.getPhoto({
    quality: 90,
    allowEditing: true,
    resultType: 'uri'
  });
  // image.webPath will contain a path that can be set as an image src
  imageElement.src = image.webPath;
}
  1. Using the Geolocation API:
import { Plugins } from '@capacitor/core';
const { Geolocation } = Plugins;

async function getCurrentPosition() {
  const coordinates = await Geolocation.getCurrentPosition();
  console.log('Current position:', coordinates.coords);
}
  1. Storing data using Preferences:
import { Plugins } from '@capacitor/core';
const { Preferences } = Plugins;

async function storeUserPreferences() {
  await Preferences.set({
    key: 'user_theme',
    value: 'dark'
  });
}

async function getUserPreferences() {
  const { value } = await Preferences.get({ key: 'user_theme' });
  console.log('User theme:', value);
}

Getting Started

  1. Install Capacitor in your project:

    npm install @capacitor/core @capacitor/cli
    
  2. Initialize Capacitor in your project:

    npx cap init
    
  3. Add platforms:

    npx cap add android
    npx cap add ios
    
  4. Build your web app and sync with Capacitor:

    npm run build
    npx cap sync
    
  5. Run your app:

    npx cap run android
    npx cap run ios
    

Competitor Comparisons

113,668

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

Pros of Electron

  • More mature and widely adopted, with a larger ecosystem and community support
  • Native access to Node.js APIs, allowing for deeper system integration
  • Better suited for complex desktop applications with heavy computational needs

Cons of Electron

  • Larger application size due to bundling Chromium and Node.js
  • Higher memory consumption, which can impact performance on low-end devices
  • Less suitable for mobile app development compared to Capacitor

Code Comparison

Electron (main process):

const { app, BrowserWindow } = require('electron')

function createWindow () {
  const win = new BrowserWindow({ width: 800, height: 600 })
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

Capacitor (web app):

import { Plugins } from '@capacitor/core';
const { Device } = Plugins;

async function getDeviceInfo() {
  const info = await Device.getInfo();
  console.log(info);
}

Electron is better suited for desktop applications with native system access, while Capacitor excels in cross-platform mobile development with a web-first approach. Electron offers more direct control over the application environment, whereas Capacitor provides a unified API for accessing native features across different platforms.

A framework for building native applications using React

Pros of React Native

  • Larger community and ecosystem, with more third-party libraries and resources
  • Better performance for complex, animation-heavy apps
  • More mature and battle-tested in production environments

Cons of React Native

  • Steeper learning curve, especially for developers new to React
  • More complex setup and configuration process
  • Less seamless integration with native platform features

Code Comparison

React Native:

import React from 'react';
import { View, Text } from 'react-native';

const App = () => (
  <View>
    <Text>Hello, React Native!</Text>
  </View>
);

Capacitor:

<ion-app>
  <ion-content>
    <h1>Hello, Capacitor!</h1>
  </ion-content>
</ion-app>
import { Capacitor } from '@capacitor/core';

const platform = Capacitor.getPlatform();
console.log(`Running on: ${platform}`);

Summary

React Native offers a more robust ecosystem and better performance for complex apps, but comes with a steeper learning curve. Capacitor provides easier integration with web technologies and simpler setup, making it more accessible for web developers transitioning to mobile app development. The choice between the two depends on project requirements, team expertise, and desired app complexity.

⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.

Pros of NativeScript

  • Direct access to native APIs without plugins
  • Truly native UI components for better performance
  • Supports both Angular and Vue.js frameworks

Cons of NativeScript

  • Steeper learning curve for developers new to mobile development
  • Smaller community and ecosystem compared to Capacitor
  • Limited web-based development options

Code Comparison

NativeScript (TypeScript):

import { Button } from "@nativescript/core";

export function createButton() {
    const button = new Button();
    button.text = "Click me";
    return button;
}

Capacitor (JavaScript):

import { Plugins } from '@capacitor/core';
const { Haptics } = Plugins;

async function triggerHaptic() {
    await Haptics.vibrate();
}

NativeScript focuses on creating native UI components directly, while Capacitor provides a bridge to access native functionality from web-based applications. NativeScript's approach results in more native-like performance and appearance, but requires more platform-specific knowledge. Capacitor, on the other hand, allows developers to leverage their existing web development skills and provides a more familiar development experience for those coming from web backgrounds.

Both frameworks have their strengths and are suitable for different project requirements and developer preferences. NativeScript is ideal for projects requiring high performance and a truly native look and feel, while Capacitor is better suited for teams with strong web development skills looking to create cross-platform mobile apps with a unified codebase.

8,578

Remote Administration Tool for Windows

Pros of Quasar

  • Comprehensive UI component library with Material Design and iOS-style components
  • Built-in support for server-side rendering (SSR) and static site generation (SSG)
  • Flexible build system with support for SPA, PWA, SSR, and mobile apps from a single codebase

Cons of Quasar

  • Steeper learning curve due to its extensive feature set
  • Less native plugin ecosystem compared to Capacitor
  • Potentially larger bundle size for simple applications

Code Comparison

Quasar (Vue.js-based):

<template>
  <q-page>
    <q-btn color="primary" label="Click me" @click="showNotification" />
  </q-page>
</template>

<script>
export default {
  methods: {
    showNotification() {
      this.$q.notify('Hello from Quasar!')
    }
  }
}
</script>

Capacitor (Framework-agnostic):

import { Plugins } from '@capacitor/core';
const { Toast } = Plugins;

async function showToast() {
  await Toast.show({
    text: 'Hello from Capacitor!'
  });
}

Summary

Quasar offers a more comprehensive framework for building cross-platform applications with Vue.js, including a rich UI component library and built-in SSR support. Capacitor, on the other hand, provides a more flexible, framework-agnostic approach for adding native functionality to web apps. The choice between the two depends on your specific project requirements and preferred development stack.

83,441

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

Pros of Tauri

  • Smaller app size and better performance due to native system bindings
  • Supports multiple programming languages for backend logic (Rust, JavaScript, TypeScript)
  • Enhanced security with a smaller attack surface

Cons of Tauri

  • Less mature ecosystem compared to Capacitor
  • Limited mobile platform support (primarily focused on desktop)
  • Steeper learning curve, especially for developers new to Rust

Code Comparison

Capacitor (JavaScript):

import { Plugins } from '@capacitor/core';
const { Device } = Plugins;

async function getDeviceInfo() {
  const info = await Device.getInfo();
  console.log(info);
}

Tauri (Rust):

#[tauri::command]
fn get_device_info() -> String {
  format!("OS: {}", std::env::consts::OS)
}

fn main() {
  tauri::Builder::default()
    .invoke_handler(tauri::generate_handler![get_device_info])
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Both Capacitor and Tauri aim to bridge web technologies with native capabilities, but they take different approaches. Capacitor focuses on mobile and web platforms, offering a more familiar environment for web developers. Tauri, on the other hand, emphasizes desktop applications with a focus on performance and security, leveraging Rust's capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


⚡️ Cross-platform apps with JavaScript and the Web ⚡️


Capacitor lets you run web apps natively on iOS, Android, Web, and more with a single codebase and cross-platform APIs.

Capacitor provides a cross-platform API and code execution layer that makes it easy to call Native SDKs from web code and to write custom native plugins that your app may need. Additionally, Capacitor provides first-class Progressive Web App support so you can write one app and deploy it to the app stores and the mobile web.

Capacitor comes with a Plugin API for building native plugins. Plugins can be written inside Capacitor apps or packaged into an npm dependency for community use. Plugin authors are encouraged to use Swift to develop plugins in iOS and Kotlin (or Java) in Android.

Getting Started

Capacitor was designed to drop-in to any existing modern web app. Run the following commands to initialize Capacitor in your app:

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

Next, install any of the desired native platforms:

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

New App?

For new apps, we recommend trying the Ionic Framework with Capacitor.

To begin, install the Ionic CLI (npm install -g @ionic/cli) and start a new app:

ionic start --capacitor

FAQ

What are the differences between Capacitor and Cordova?

In spirit, Capacitor and Cordova are very similar. Capacitor offers backward compatibility with a vast majority of Cordova plugins.

Capacitor and Cordova differ in that Capacitor:

  • takes a more modern approach to tooling and plugin development
  • treats native projects as source artifacts as opposed to build artifacts
  • is maintained by the Ionic Team 💙😊

See the docs for more details.

Do I need to use Ionic Framework with Capacitor?

No, you do not need to use Ionic Framework with Capacitor. Without the Ionic Framework, you may need to implement Native UI yourself. Without the Ionic CLI, you may need to configure tooling yourself to enable features such as livereload. See the docs for more details.

Contributing

See CONTRIBUTING.md.

Contributors

Made possible by the Capacitor community. 💖

NPM DownloadsLast 30 Days