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.
Daya
DayaSoftware Engineer - I
lines

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.

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:

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

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

Include this mod in your app.json:

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

Include this custom plugin in your app.json:

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! 🚀

Hire our Development experts.