在 Expo(或更广义的 React Native managed workflow)里,Config Plugin(配置插件)是一种机制,允许你在不 eject(弹出)出“纯 JS”项目的情况下,对底层 iOS/Android 原生配置做定制化改动。
Info.plist
, AndroidManifest.xml
, Gradle
配置时,需要把项目 eject 成 bare workflow. Config Plugin 则让你留在 managed workflow 里,继续享受 OTA 更新、简单的 JS-only 开发体验。withXxx
系列 HOC 去修改 iOS/Android 原生项目文件。app.json
或 app.config.js
里声明 plugins: [...]
。在 app.config.js
中注册插件
// app.config.js
import { ExpoConfig, ConfigContext } from '@expo/config';
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: "MyApp",
slug: "my-app",
version: "1.0.0",
plugins: [
// 官方社区插件
'expo-build-properties',
// 自定义本地插件
'./plugins/with-custom-splash.js',
],
});
一个简单的自定义插件
// plugins/with-custom-splash.js
const { withSplashScreen } = require('@expo/config-plugins');
module.exports = function withCustomSplash(config) {
return withSplashScreen(config, {
image: './assets/splash-custom.png',
resizeMode: 'cover',
backgroundColor: '#ffffff',
});
};
这里,withSplashScreen
底层会修改 iOS 的 LaunchScreen.storyboard
, Android 的 launch_background.xml
,并把你指定的图片、背景色等属性写进去。
expo-build-properties
:配置 Android Gradle or iOS Pod 的版本、构建属性@react-native-google-signin/google-signin
:一键注入必要的原生依赖和 Manifest/Info.plist
配置sentry-expo
:集成 Sentry,自动注入DSN
、Gradle
脚本等config
,要返回修改过的 config
。