See how Capacitor fits into the entire Ionic Ecosystem ->
Capacitor is part of the Ionic Ecosystem ->
React

Stencil & Capacitor

Build native mobile apps with web technology and Stencil

Get Started
01

Install Capacitor.

Add Capacitor to your project and create a config for your app

npm install @capacitor/core @capacitor/cli
npx cap init [name] [id] --webDir=www
02

Build the Web App.

The compiled web assets will be copied into each Capacitor native platform during the next step.

npm run build
03

Install the native platforms you want to target.

AppleAndroid

Capacitor's native projects exist in their own top-level folders and should be considered part of your app (check them into source control).

npx cap add android
npx cap add ios
04

Adding calls to Native APIs

With Capacitor installed, adding calls to native device features is as straight forward as calling other JavaScript methods

import { Component, Host, State, h } from '@stencil/core';
import { Plugins } from '@capacitor/core';

@Component({
  tag: 'geolocation-page',
  shadow: true,
})
export class  GeolocationPage() {

  @State() loc = null;

  async getCurrentPosition() {
    const { Geolocation } = Plugins;
    const loc = await Geolocation.getCurrentPosition();
    this.loc = loc;
  }

  render() {
    return (
      
        

Geolocation

Your location is:

Latitude: {this.loc?.coords.latitude}

Longitude: {this.loc?.coords.longitude}

); } }

Continue your Capacitor Journey.

This is only the beginning. Learn more about the Capacitor development workflow or using more native APIs .