Skip to main content

Plugin Development Workflow

With the plugin scaffolded, you can implement functionality across the web and the C# side.

Implementing a New Method​

Begin by defining the method's signature in src/definitions.ts:

export interface EchoPlugin {
echo(options: { value: string }): Promise<{ value: string }>;
+ openMap(options: OpenMapOptions): Promise<void>;
}

+export interface OpenMapOptions {
+ latitude: number;
+ longitude: number;
+}

Implement the web version in src/web.ts:

export class EchoWeb implements EchoPlugin {
// other methods

+ async openMap(options: OpenMapOptions): Promise<void> {
+ // logic here
+ }
}

Implement the native version in maui/EchoPlugin.cs — one implementation covers all platforms:

[NapacitorPlugin("Echo")]
public class EchoPlugin : NapacitorPluginBase
{
+ [NapacitorMethod]
+ public async Task OpenMap(OpenMapOptions options)
+ {
+ await Map.Default.OpenAsync(new Location(options.Latitude, options.Longitude));
+ }
}

+public class OpenMapOptions
+{
+ public double Latitude { get; set; }
+ public double Longitude { get; set; }
+}

Build the JS artifact (CJS + .d.ts are committed in dist/):

npm run build

This example covers the most common method shape; all supported shapes are described in Method Types.

Local Testing​

To test the plugin locally, link the plugin folder to your app:

npm install ../path/to/echo

The app's package.json now shows:

"echo": "file:../path/to/echo"

Then run nap sync so the host's napacitor.build.props picks up the plugin's C# project, and run the app:

npx nap sync
npx nap run --target android

Unlink with npm uninstall echo.

Documentation​

Document plugin functionality with JSDoc comments on definitions.ts — the package README's API section should mirror the exported interface (methods, parameters, interfaces, and events). Include any host-side setup steps consumers must perform (permissions, URL schemes, MauiProgram forwarding for plugins such as App Actions).

Publishing​

Napacitor plugins are published like any npm package. The dist/ build output is committed so consumers get CJS + .d.ts without a build step:

npm publish

The package can then be installed in any app:

npm install @your-scope/echo
npx nap sync

Note: Napacitor beta releases use peer dependencies such as @napacitor/core@^0.1.0. Consumers installing prerelease versions may need npm install --legacy-peer-deps (see Troubleshooting).