Skip to content

Commit

Permalink
Merge pull request #1129 from nxext/capacitor-docs-overview
Browse files Browse the repository at this point in the history
docs: add capacitor overview
  • Loading branch information
edbzn authored Oct 10, 2024
2 parents ddb9de9 + bafbb11 commit db7c6a2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ function sideNavDocs() {
collapsible: true,
collapsed: true,
items: [
{
text: 'Overview',
link: '/docs/capacitor/overview',
},
{
text: 'Generators',
link: '/docs/capacitor/generators',
},
{
text: 'Executors',
link: '/docs/stencil/executors',
link: '/docs/capacitor/executors',
},
],
},
Expand Down
92 changes: 92 additions & 0 deletions docs/docs/capacitor/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
The `@nxext/capacitor` plugin lets you interact with the Capacitor CLI using Nx targets.

## Install Plugin

```
# npm
npm install --save-dev --exact @nxext/capacitor
# yarn
yarn add --save-dev --exact @nxext/capacitor
```

## Add Capacitor to Existing Project

First, ensure that the frontend project has been built:

```
nx build {frontend project name}
nx build mobile-app
```

Once the plugin has been added to your Nx workspace you can generate a Capacitor project from an existing frontend project:

```
nx generate @nxext/capacitor:configuration --project {frontend project name}
nx generate @nxext/capacitor:configuration --project mobile-app
```

Nx will ask you some questions about the application, but you can customize it further by passing these options:

```
nx generate @nxext/capacitor:configuration [options,...]
Options:
--project The name of the frontend project for Capacitor.
--appId The app ID for the project. (default: io.ionic.starter)
--appName The application name for the project.
--webDir The directory of your projects built web assets.
--skipFormat Skip formatting files.
--dryRun Runs through and reports activity without writing to disk.
--skip-nx-cache Skip the use of Nx cache.
--help Show available options for project target.
```

Finally, you will need to `cd` into your applications directory and install the npm dependencies. (e.g. `npm install`)

## Add Native Platforms

Now that a Capacitor project has been added to your Nx workspace you can begin adding support for native platforms. Currently, Capacitor supports Android and iOS, but other platforms can be added with Capacitor plugins.

```
nx run {frontend project}:add:ios
nx run {frontend project}:add:android
nx run {frontend project}:add --platform {native platform}
nx run my-app:add:android
nx run my-app:cap --cmd="add android"
```

## Sync Native Platform

Running the sync command will update the native platform dependencies and copy a build of your frontend project to the Capacitor project:

```
nx run {frontend project}:sync:ios
nx run {frontend project}:sync:android
nx run {frontend project}:sync --platform {native platform}
nx run my-app:sync:android
nx run my-app:cap --cmd="sync android"
```

## Open Native Platform

Finally, you can open the native platform in it's respective IDE:

```
nx run {frontend project}:open:ios
nx run {frontend project}:open:android
nx run {frontend project}:open --platform {native platform}
nx run my-app:open:android
nx run my-app:cap --cmd="open android"
```

## Adding Capacitor Plugins

Capacitor plugin dependencies must be added to the project-level `package.json`.

To learn more about Capacitor, including the native API's available, please read the [official Capacitor documentation](https://capacitorjs.com/docs).

0 comments on commit db7c6a2

Please sign in to comment.