Skip to content

Instantly share code, notes, and snippets.

@sixman9
Last active February 3, 2022 21:53
Show Gist options
  • Save sixman9/3332e8e6c693dc7da50f30e021d1e687 to your computer and use it in GitHub Desktop.
Save sixman9/3332e8e6c693dc7da50f30e021d1e687 to your computer and use it in GitHub Desktop.
Wrapping a Web app or PWA into an Ionic/Capacitor Mobile or Desktop app

Capacitor—How To Get Five Apps In One time

Use Ionic framework ‘Capacitor’ to write Angular 7 code and create apps for PWA, iOS, Android, MacOS, and Windows in one go.

Jeroen Ouwehand

Nov 11, 2018·3 min read

https://medium.com/@jeroenouw/capacitor-how-to-get-five-apps-in-one-time-636d2fc7026a

Image for post

by Helloquence on Unsplash

Are you also a lazy developer? And do you want to create multiple apps with only doing the effort ones? And you don’t want to learn languages like Java and Swift? Please consider Capacitor. An Ionic framework (which uses Angular) for creating a cross-platform app at runtime that makes it easy to build web apps that run natively on iOS, Android, Electron, and the web. We call these apps “Native Progressive Web Apps” and they represent the next evolution beyond Hybrid apps.

Capacitor 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 on platforms that support them. Adding native functionality is easy with a simple Plugin API for Swift on iOS, Java on Android, and JavaScript for the web.

Capacitor in six points:

  • Cross Platform
  • Native Access
  • Use with Ionic and Angular 7
  • Web Native
  • Extensible with Plugins
  • Open Source (MIT)

Basic steps to get you started (example project)

We are going to install the Angular CLI, Ionic and npx globally, create a new Angular 7 project and then install the dependencies: Capacitor Core and CLI. After this, we initialize Capacitor into our new project.

Note: the project in this post will be empty, this is just to show you how to generate the project and build all the different apps.

npm install @angular/cli ionic npx -g #Replace Angular with ReactJS

ng new capacitor-app #Replace with ReactJS project setup

cd capacitor-app

npm install @capacitor/core @capacitor/cli --save

npx cap init

PWA — Progressive Web App

To build a PWA, make sure to have the following configurations set:

  • In your angular.json file:
outputPath = “www”
  • In your capacitor.config.json file:
webDir = “www”   
bundledWebRuntime = “false”

After this you can run:

ng build --prod  
npx cap serve

iOS

npx cap add ios  
npx cap copy ios  
npc cap run ios

Android

npx cap add android  
npx cap copy android  
npc cap run android

MacOS & Windows

Make sure to have this in your index.html :

<base href="./">

Now you can run:

ng build --prod  
npx cap add electron  
cd electron  
npm run electron:start

After running all the commands in the command line, you have five different apps made in no time with only coding one app. You can now start developing your Capacitor project!

Thank you for reading! My Github. If you found this post useful, consider reading some of my other articles:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment