Jan 18, 2024

Unlocking Expo's Power: A Guide to Config Plugins and Mods

Ready to upgrade your Expo projects? By adding configuration plugins and mods, you can customize Expo to suit your needs.

Author

DayaDayaSoftware Engineer III
Unlocking Expo's Power: A Guide to Config Plugins and Mods

In this article, we will be exploring how to use Expo to its fullest potential and also look at some tools to make it easier. 


The Role of Config Plugins and Mods

Expo projects often require tweaks like:

  • Adding third-party libraries
  • Modifying native configuration files
  • Injecting custom code and settings

Doing this directly complicates maintenance. Enter config plugins and mods!

Config plugins extend Expo's capabilities in a maintainable way. They modify the Expo config during the pre-build phase.

Mods handle automatically changing native files like AndroidManifest.xml. They abstract away these complexities.

The need for config plugins and mods in Expo arises from the desire for customization, maintainability, compatibility across different workflows, and the efficient automation of configurations.

These tools empower developers to add functionality, customize native configurations, enhance cross-platform development, and simplify their development workflows.

The Role of Config Plugins and Mods

Together, they facilitate customization without compromising stability. Let's see them in action!


Understanding Config Plugins

Config plugins are essential for extending app configurations and customizing the pre-build process according to your specific requirements. To better understand this, let's examine the fundamental structure of an ExpoConfig object before delving into the intricate details.

{
  "name": "config-plugins",
  "slug": "config-plugins",
  "version": "1.0.0",
  // ... other properties ...
  "plugins": [
    ["./plugins/build/withReactNativeContacts.js"],
    "expo-camera"
  ],
  // ... platform-specific configurations ...
}

Anatomy of a Config Plugin

A configuration plugin is essentially a synchronous function that takes an object of ExpoConfig as input and produces a modified object of ExpoConfig as output. By following a naming convention, such as with<PluginFunctionality>, these plugins offer limitless possibilities for customization. Let's explore a practical example:

const withApplicationBuildGradle: ConfigPlugin = config => {
  return withAppBuildGradle(config, async config => {
    // Add the 'implementation' configuration to the dependencies in the correct block
    const dependenciesBlock = 'dependencies {';
    const implementationLine =
      "    implementation project(':react-native-contacts')";

    if (config.modResults.contents.includes(dependenciesBlock)) {
      // If 'dependencies' block is found, append the implementation line
      config.modResults.contents = config.modResults.contents.replace(
        dependenciesBlock,
        `${dependenciesBlock}\n${implementationLine}`
      );
    }

    return config;
  });

  return config;
};

export default withReactNativeContacts;

// Main custom config plugin
const withReactNativeContacts = (config: ExpoConfig) => {
  // Apply the AppBuildgradle mod
  config = withApplicationBuildGradle(config);

  return config;
};

export default withReactNativeContacts;

To integrate this plugin, simply add it to your app.json:

{
  "expo": {
    "name": "config-plugins",
    "plugins": [["./plugins/build/withReactNativeContacts.js"]],
    // ... other configurations ...
  }
}

When you run npx expo prebuild --clean with this setup, the plugin will modify native files seamlessly.


Mastering Mods

Mods, or modifiers, are asynchronous functions designed to manipulate native project files during code generation. While they might seem daunting initially, Expo provides helper mods for common tasks like working with AndroidManifest.xml and Info.plist.

Real-world Example Mod: withMainApplication

const withReactNativeContacts: ConfigPlugin = config => {
  config = withMainApplication(config, async config => {
    if (
      config.modResults.language === 'java' &&
      config.modResults.contents.includes('MainApplication')
    ) {
      const reactNativeContactsImport =
        'import com.rt2zz.reactnativecontacts.ReactNativeContacts;';
      const reactNativeContactsPackage = 'new ReactNativeContacts()';

      if (!config.modResults.contents.includes(reactNativeContactsImport)) {
        // Add the import statement
        config.modResults.contents = config.modResults.contents.replace(
          'import com.facebook.react.ReactApplication;',
          `import com.facebook.react.ReactApplication;\n${reactNativeContactsImport}`
        );
      }

      if (!config.modResults.contents.includes(reactNativeContactsPackage)) {
        // Add the ReactNativeContacts package to the list
        config.modResults.contents = config.modResults.contents.replace(
          'return packages;',
          `packages.add(${reactNativeContactsPackage});\n        return packages;`
        );
      }
    }

    return config;
  });

  return config;
};

export default withReactNativeContacts;

Include this mod in your app.json:

{
  "expo": {
    "plugins": [["./plugins/build/withReactNativeContacts.js"]],
    // ... other configurations ...
  }
}

Executing npx expo prebuild --clean with this setup applies the mod, injecting "MY_CUSTOM_API_KEY" into Info.plist.


Types of Packages in Expo

Let's begin by clarifying the difference between Managed Expo Packages and Bare Workflow Packages before we explore more examples.

Managed Expo Packages

These packages can be easily integrated into Expo projects by adding them to the plugin array in app.json. Expo will take care of any necessary native configuration changes.

Bare Workflow Packages

Packages that are not Expo-aware require custom configuration for integration. Developers can enter custom config plugins, which modify native code during the pre-build process while keeping the application Expo-managed.


Real-world Examples: Putting It All Together

// Custom config plugin for react-native-contacts
import { ExpoConfig } from '@expo/config-types';
import {
  withAndroidManifest,
  withInfoPlist,
  ConfigPlugin,
} from 'expo/config-plugins';

// Mod to add Android permissions to the manifest
const withAndroidPermissions: ConfigPlugin = config => {
  return withAndroidManifest(config, async config => {
    const permissionsToAdd = [
      'android.permission.READ_CONTACTS',
      'android.permission.WRITE_CONTACTS',
    ];

    permissionsToAdd.forEach(permission => {
      const existingPermission = config.modResults.manifest[
        'uses-permission'
      ]?.find(p => p['$'] && p['$']['android:name'] === permission);

      if (!existingPermission) {
        config.modResults.manifest['uses-permission'] =
          config.modResults.manifest['uses-permission'] ?? [];
        config.modResults.manifest['uses-permission'].push({
          $: {
            'android:name': permission,
          },
        });
      }
    });

    return config;
  });
};

// Mod to add iOS usage description to Info.plist
const withIosPermissions: ConfigPlugin = config => {
  return withInfoPlist(config, async config => {
    if (!config.modResults.NSContactsUsageDescription) {
      config.modResults.NSContactsUsageDescription =
        'Your app uses contacts to provide important functionality';
    }
    return config;
  });
};

// Main custom config plugin
const withReactNativeContacts = (config: ExpoConfig) => {
  // Apply the AndroidManifest mod
  config = withAndroidPermissions(config);

  // Apply the Info.plist mod
  config = withIosPermissions(config);
  return config;
};

export default withReactNativeContacts;

Include this custom plugin in your app.json:

{
  "expo": {
    "plugins": [["./withReactNativeContacts.js"]],
    // ... other configurations ...
  }
}

Running npx expo prebuild --clean applies the mods, making necessary changes to AndroidManifest.xml and Info.plist.


Going Above and Beyond

Config plugins and mods empower Expo developers to shape their projects according to specific requirements. Whether dealing with Managed Expo Packages or Bare Workflow Packages, these tools offer a robust framework for customization.

For business owners, the process discussed has three advantages:

  1. Better Flexibility: Tech teams can use more fancy libraries and tools to make apps better. That means faster development with more awesome features.
  2. Increased Efficiency: Config plugins and mods do all the hard work for us when it comes to making changes to the native code. No more manual errors or wasting time trying to figure things out ourselves.
  3. Easier Maintainability: With config plugins, everything stays nice and organized within our project. We won't get lost or confused because it's easy to understand what's going on with our native code.

Basically, any app we build using Expo that needs special libraries with native code changes can benefit from config plugins and mods.

Experiment with these examples, explore the documentation, and unlock the full potential of Expo config plugins and mods in your projects! Happy coding! 🚀

Subscribe to Our Newsletter

RELATED ARTICLES

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari
The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari
A real-world look at how oversized images can trigger Safari reloads and iOS crashes in Flutter apps and how smarter image decoding prevents them.
From Prompting to Process: What Changed When Flutter Shipped Agent Skills
From Prompting to Process: What Changed When Flutter Shipped Agent Skills
This blog explores how Flutter Agent Skills improve AI-assisted development by combining official framework workflows with project-specific guidance for more consistent development.
Why Everything Your AI Builds Looks the Same
Why Everything Your AI Builds Looks the Same
This blog explores why AI-generated interfaces often look alike and explains how design systems, product context, and reusable engineering practices help teams build distinctive, scalable
How We Built the Missing Bridge from Code to Figma
Technology

Jul 10, 2026

How We Built the Missing Bridge from Code to Figma
This blog explores how AI-generated React apps get turned into fully editable, designer-ready Figma files by reading React Fiber instead of the DOM.
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability
Technology

Jun 27, 2026

Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability
A practical breakdown of building resilient AWS-to-on-premises connectivity with WireGuard HA, active-standby failover, and deep packet-forwarding observability.
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
Technology

Jun 19, 2026

We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
A practical guide to building a 114-second multi-cloud disaster recovery failover between AWS and Azure — what we built, what broke, and what we learned.
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
Technology

Jun 12, 2026

Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
This blog explains how organizations can balance speed, scalability, and operational flexibility as they grow from startup to enterprise scale.

The Right Conversation Can Save You Six Months.

Whether you’re navigating AI adoption, modernizing legacy systems, or scaling a product - we start by listening. No pitch deck. No template. A real conversation.