Plugin structure and exports
A config plugin is a function with this signature:Plugin.types.ts
Basic plugin
The simplest plugin takes a config and returns it:Plugin with props
Plugins can accept typed props:app.json:
Naming conventions
Follow these naming conventions from the Expo ecosystem:Function names
Start plugin functions withwith:
- Debugging: Stack traces show clear plugin names
- Consistency: Matches Expo’s built-in plugins
- Convention: Indicates the function is a config plugin
File names
For plugin files:Creating your first plugin
Let’s create a plugin that adds a custom URL scheme to your app. Createplugins/withCustomScheme.ts:
plugins/withCustomScheme.ts
app.json:
app.json
myapp:// URL scheme on both platforms.
TypeScript types
Expo provides comprehensive TypeScript types for config plugins.Core types
Plugin.types.ts
File type definitions
Helper to extract plugin parameter types
Plugin.types.ts
Plugin helpers
createRunOncePlugin
Prevent a plugin from running multiple times:withRunOnce.ts
- Preventing duplicate modifications
- Migrating from unversioned to versioned plugins
- Tracking plugin history
createInfoPlistPlugin
Helper for iOS Info.plist modifications:ios-plugins.ts
createAndroidManifestPlugin
Helper for Android manifest modifications:android-plugins.ts
createEntitlementsPlugin
Helper for iOS entitlements:ios-plugins.ts
Composing multiple plugins
Plugins can chain other plugins:Error handling
UsePluginError for better error messages:
Exporting plugins from packages
For npm packages, export your plugin from aplugin directory:
app.json:
my-library/plugin.
Best practices
1. Keep plugins pure
Plugins should be deterministic:2. Document your props
Use JSDoc comments:3. Validate props early
4. Avoid side effects
Don’t write files or make network requests during plugin execution. Use mods instead:5. Use helpers for common tasks
Leverage built-in helpers likecreateInfoPlistPlugin, createAndroidManifestPlugin, etc.
Next steps
- Plugin API reference - Complete API documentation
- Modifying native projects - Deep dive into iOS and Android modifications
- Testing plugins - Test your plugins effectively