|
| 1 | +# Minification |
| 2 | + |
| 3 | +This guide shows how to enable minification for both Expo and bare React Native brownfield modules. |
| 4 | + |
| 5 | +## Expo |
| 6 | + |
| 7 | +Configure minification through the Brownfield config in `package.json` and let `expo prebuild` apply it to the generated module. |
| 8 | + |
| 9 | +Steps: |
| 10 | + |
| 11 | +1. Add a `brownfield` block to `package.json` and enable `android.expo.minifyEnabled`. |
| 12 | +2. Add keep rules in `android.expo.extraProguardRules` for generated Brownie store types, navigation types, and host manager classes you need to keep. |
| 13 | +3. Run `expo prebuild` to regenerate the Android module with the new settings. |
| 14 | + |
| 15 | +Example (see `apps/ExpoApp56`): |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "brownfield": { |
| 20 | + "debug": true, |
| 21 | + "android": { |
| 22 | + "expo": { |
| 23 | + "minifyEnabled": true, |
| 24 | + "extraProguardRules": [ |
| 25 | + "-keep class com.callstack.rnbrownfield.demo.expoapp56.BrownfieldStore { *; }", |
| 26 | + "-keep class com.callstack.rnbrownfield.demo.expoapp56.BrownfieldStore$Companion { *; }", |
| 27 | + "-keep class com.callstack.rnbrownfield.demo.expoapp56.User { *; }", |
| 28 | + "-keep class com.callstack.rnbrownfield.demo.expoapp56.SettingsStore { *; }", |
| 29 | + "-keep class com.callstack.rnbrownfield.demo.expoapp56.SettingsStore$Companion { *; }", |
| 30 | + "-keep class com.callstack.rnbrownfield.demo.expoapp56.Theme { *; }", |
| 31 | + "-keep class com.callstack.nativebrownfieldnavigation.UserType { *; }" |
| 32 | + ] |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +## Bare React Native |
| 40 | + |
| 41 | +For bare React Native, you do not need any Brownfield config. Enable minification in the module itself and add Proguard rules manually. |
| 42 | + |
| 43 | +Steps: |
| 44 | + |
| 45 | +1. In your `brownfieldlib/build.gradle.kts`, enable `isMinifyEnabled = true` in the `release` build type. |
| 46 | +2. Ensure `proguard-rules.pro` keeps the generated Brownie store types, navigation types, and your host manager if you have one. |
| 47 | + |
| 48 | +Example (see `apps/RNApp`): |
| 49 | + |
| 50 | +```kts |
| 51 | +android { |
| 52 | + buildTypes { |
| 53 | + release { |
| 54 | + isMinifyEnabled = true |
| 55 | + proguardFiles( |
| 56 | + getDefaultProguardFile("proguard-android-optimize.txt"), |
| 57 | + "proguard-rules.pro" |
| 58 | + ) |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +``` |
| 65 | +-keep class com.rnapp.brownfieldlib.BrownfieldStore { *; } |
| 66 | +-keep class com.rnapp.brownfieldlib.BrownfieldStore$Companion { *; } |
| 67 | +-keep class com.rnapp.brownfieldlib.User { *; } |
| 68 | +-keep class com.rnapp.brownfieldlib.SettingsStore { *; } |
| 69 | +-keep class com.rnapp.brownfieldlib.SettingsStore$Companion { *; } |
| 70 | +-keep class com.rnapp.brownfieldlib.Theme { *; } |
| 71 | +-keep class com.rnapp.brownfieldlib.ReactNativeHostManager { *; } |
| 72 | +
|
| 73 | +-keep class com.callstack.nativebrownfieldnavigation.UserType { *; } |
| 74 | +``` |
0 commit comments