App Setup
Last updated
Was this helpful?
Last updated
Was this helpful?
There are two ways to create your Capacitor application. You can use the @capacitor/create-app
package to create a Capacitor application from scratch, or you can add Capacitor to your already existing web project.
Remember to make sure your for the platforms you will be building for.
The @capacitor/create-app
package can be used to quickly create a Capacitor application. You can run the following command in an empty directory to scaffold a new Capacitor application.
Copy
Capacitor was designed to drop into any modern JavaScript web app. However, your project needs to have the following three requirements in order to use Capacitor with your existing application.
Your project must have...
A package.json
file
A separate directory for built web assets such as dist
or www
An index.html
file at the root of your web assets directory
Info
Your index.html
file must have a <head>
tag in order to properly inject Capacitor. If you do not have a <head>
in your Html, Capacitor plugins will not work.
In the root of your app, install Capacitor's main npm depdencies: the core JavaScript runtime and the command line interface (CLI).
Copy
Then, initialize Capacitor using the CLI questionnaire:
Copy
The CLI will ask you a few questions, starting with your app name, and the package ID you would like to use for your app.
After the Capacitor core runtime is installed, you can install the Android and iOS platforms.
Copy
Once the platforms have been added to your package.json
, you can run the following commands to create your Android and iOS projects for your native application.
Copy
Once you've created your native projects, you can sync your web application to your native project by running the following command.
Copy
npx cap sync
will copy your built web application, by default www
, to your native project and install the native projects dependencies.