Search code examples
cordovamobilegatsbyphonegapcapacitor

How can I build mobile apps from my Gatsby web app?


I have built a Gatsby web app and am now trying to build an Android and iOS mobile app from the same code base.

Is there a way to do this, maybe with Apache Cordova / Capacitor? And if so, how do I do it?


Solution

  • Yes, this is absolutely possible!

    Capacitor, the spiritual successor to Apache Cordova and Adobe PhoneGap, can be used for this purpose.

    For an existing project:

    1. Install and configure Capacitor as described in its Getting Started docs.
    2. Change the webDir to public in the capacitor.config.json file.
    3. Add the required platforms and run the app on your mobile device.

    Check out this article about building fast mobile apps using Gatsby and Capacitor for a more detailed step by step manual.

    For a new project:

    If you are planning to build a new hybrid app using Gatsby and Capacitor you might want to use the gatsby-starter-capacitor Gatsby starter to speed up the process.

    Just run gatsby new my-gatsby-capacitor-project https://github.com/flogy/gatsby-starter-capacitor to get a fully functional Gatsby app that can be run on mobile and that even uses native functionality.