Skip to main content

Installing Napacitor

You can create a new Napacitor application or add Napacitor to your existing web project.

Remember to make sure your environment is set up for the platforms you will be building for.

Add Napacitor to your web app​

Napacitor was designed to drop into any JavaScript web app. However, your project needs to have the following three requirements in order to use Napacitor with your existing application:

  • 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 Napacitor. If you do not have a <head> in your Html, Napacitor plugins will not work.

Install Napacitor​

In the root of your app, install Napacitor's main npm dependencies: the core JavaScript runtime, the MAUI runtime (C# sources), and the command line interface (CLI).

npm i @napacitor/core
npm i -D @napacitor/maui @napacitor/cli

Initialize your Napacitor config​

Then, initialize Napacitor:

npx nap init com.example.app "My App" --web-dir dist

The CLI is non-interactive: pass the app id, app name, and the expected output directory of your bundler (e.g. dist for Vite, www for Angular). It creates napacitor.config.json with these configuration details.

info

You can customize the folder used by Napacitor by modifying the webDir variable in the napacitor.config.json file that is created during npx nap init. It is a good idea to cross-check this variable when having issues syncing your first build.

Create your MAUI host project​

npx nap add maui

This generates the maui/ host project — the .NET MAUI shell for your web app, targeting Android, iOS, Mac Catalyst, and Windows from one codebase. If webDir has already been built, the command also performs an initial sync.

Sync your web code to the host project​

Once you've created the host, sync your web application to it:

npm run build # if you have a build step
npx nap sync

npx nap sync copies your built web bundle from webDir to the host's wwwroot/ and regenerates napacitor.build.props, which wires every installed plugin's C# project into the host.

Run your app​

npx nap run --target android # or ios / maccatalyst / windows

On Windows, build first: npx nap build --target windows, then npx nap run --target windows.

Where to go next​

With your environment setup, and your project structure set up properly, you're ready to go! You can follow any of the links below if you need more specific documentation.

Get started with the MAUI platform ›

Developer Workflow Guide ›