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

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.

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

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Building a Real-Time Photo Sync Video Experience Using 100ms SDK and Reactive State Management
Oct 15, 2026

Building a Real-Time Photo Sync Video Experience Using 100ms SDK and Reactive State Management

This blog explains how to build a real-time video experience with synchronized photo sharing, chat, and reactive state management using the 100ms SDK.

Insight
Taming Elasticsearch at Scale
Oct 13, 2026

Taming Elasticsearch at Scale

Optimize Elasticsearch for millions of records with better pagination, leaner payloads, efficient filtering, faster ingestion, and frontend techniques that keep search responsive with increase in data.

Insight
Deep Linking for Mobile Apps(React Native) with NestJs, AWS CloudFront, S3 & ALB: A Complete Guide
Oct 13, 2026

Deep Linking for Mobile Apps(React Native) with NestJs, AWS CloudFront, S3 & ALB: A Complete Guide

Build a self-hosted deep linking and referral system for React Native without a third-party SDK. This guide covers Android App Links, iOS Universal Links, an S3 and CloudFront setup, and a NestJS backend that routes users to the right app store.

Insight
How We Engineered a Three-Path Reward Processing System for a Real-Time Sports Platform
Oct 12, 2026

How We Engineered a Three-Path Reward Processing System for a Real-Time Sports Platform

This blog explains how a real-time sports platform uses synchronous, asynchronous, and scheduled processing paths to handle rewards without slowing down the player experience.

Insight
Building an MCP-Powered QA Agent
Oct 12, 2026

Building an MCP-Powered QA Agent

Build an MCP QA agent that runs Playwright tests, validates APIs, and analyzes failures through a controlled, auditable tool layer with human approval.

Insight
From Test Failure to Root Cause: Building an AI-Assisted Playwright Failure Analysis Pipeline
Oct 9, 2026

From Test Failure to Root Cause: Building an AI-Assisted Playwright Failure Analysis Pipeline

This blog explains how an AI-assisted Playwright pipeline can analyze test failure evidence, identify probable root causes, and support human-validated debugging.

Insight
The Model Context Protocol: From First Call to Production
Oct 8, 2026

The Model Context Protocol: From First Call to Production

This blog explains how Model Context Protocol (MCP) works, from tool discovery and execution to OAuth authorization, security controls, and production deployment.

Footer

The Right Conversation Can

Save You Six Months.

Book a Call