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?
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:
webDir
to public
in the capacitor.config.json
file.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.