[Unimodules] What else can I exclude?

https://docs.expo.io/bare/installing-unimodules/

If you need to exclude some of the unimodules that you are not using but they got installed by your other dependencies (like expo ), then you can pass in exclude param for this. For example, if you want to exclude expo-face-detector , you may want to use this: use_unimodules!(exclude: ['expo-face-detector'])
If you need to exclude some of the unimodules that you are not using but they got installed by your other dependencies (like expo ), then you can pass in exclude param for this. For example, if you want to exclude expo-face-detector , you may want to use this: addUnimodulesDependencies([exclude: ['expo-face-detector']])

I would like to avoid integrating with unnecessary modules and bloating my app. Since there is only a denyList exclude option and not an allowList include option- how can I get the full list of excludable modules?

Right now I have the following:

Podfile

        # For enabling unimodules
        use_unimodules!(
          modules_paths: ...,
          exclude: [
            'expo-camera',
            'expo-constants',
            'expo-file-system',
            'expo-image-loader',
            # 'expo-local-authentication', # explicitly added for use
            'expo-payments-stripe',
            'expo-permissions',
            # 'expo-secure-store', # explicitly added for use
            'expo-video-thumbnails',
            'unimodules-app-loader',
            'unimodules-barcode-scanner-interface',
            'unimodules-camera-interface',
            # 'unimodules-constants-interface',  # required by expo-local-authentication
            'unimodules-face-detector-interface',
            'unimodules-file-system-interface',
            # 'unimodules-font-interface', # required by react-native-adapter (see https://github.com/expo/expo/blob/3d1fb0e3f94434d15c3fa70073bb496e82e7ac41/packages/%40unimodules/react-native-adapter/ios/UMReactNativeAdapter.podspec#L21)
            'unimodules-image-loader-interface',
            'unimodules-permissions-interface',
            # 'unimodules-react-native-adapter', # required for expo modules
            'unimodules-sensors-interface',
            'unimodules-task-manager-interface'
          ]

app/build.gradle

    addUnimodulesDependencies(
        modulesPaths : ['../../../node_modules'],
        exclude      : [
            'expo-camera',
            'expo-constants',
            'expo-file-system',
            'expo-image-loader',
            // 'expo-local-authentication', // explicitly added for use
            'expo-payments-stripe',
            'expo-permissions',
            // 'expo-secure-store',  // explicitly added for use
            'expo-video-thumbnails',
            // 'unimodules-app-loader', // required by react-native-adapter (android only)
            'unimodules-barcode-scanner-interface',
            'unimodules-camera-interface',
            // 'unimodules-constants-interface', // required by expo-local-authentication
            'unimodules-face-detector-interface',
            'unimodules-file-system-interface',
            // 'unimodules-font-interface', // required by react-native-adapter
            // 'unimodules-image-loader-interface', // required by react-native-adapter (android only)
            // 'unimodules-permissions-interface', // // required by react-native-adapter (android only)
            // 'unimodules-react-native-adapter', // required for expo modules
            'unimodules-sensors-interface',
            'unimodules-task-manager-interface'
        ]
    )

settings.gradle

includeUnimodulesProjects(
  modulesPaths : ['../../../node_modules'],
  exclude      : [
      'expo-camera',
      'expo-constants',
      'expo-file-system',
      'expo-image-loader',
      // 'expo-local-authentication',  // explicitly added for use
      'expo-payments-stripe',
      'expo-permissions',
      // 'expo-secure-store',  // explicitly added for use
      'expo-video-thumbnails',
      // 'unimodules-app-loader', // required by react-native-adapter (android only) 
      'unimodules-barcode-scanner-interface',
      'unimodules-camera-interface',
      // 'unimodules-constants-interface', // required by expo-local-authentication
      'unimodules-face-detector-interface',
      'unimodules-file-system-interface',
      // 'unimodules-font-interface', // required by react-native-adapter
      // 'unimodules-image-loader-interface', // required by react-native-adapter (android only)
      // 'unimodules-permissions-interface', // required by react-native-adapter (android only)
      // 'unimodules-react-native-adapter', // required for expo modules
      'unimodules-sensors-interface',
      'unimodules-task-manager-interface'
  ]
)

You don’t need to add anything to that list, includeUnimodulesProjects is loading only unimodules that are in your node modules, so if you don’t want to use some of those, just remove it from package.json (and run yarn install)

@wkozyra do you mean because I caught everything? On ios for example, I can see that any use_unimodules I dont exclude get added to Podfile.lock.

Or do you mean that unimodules and expo modules are automatically excluded? If so, is there documentation or a source or I can check to learn more about that?

On ios for example, I can see that any use_unimodules I dont exclude get added to Podfile.lock.

Yes, those scripts are adding every unimodule that is in node_modules. The recommended way to minimize number of packages like that is to make sure that they are not present in node_modules.

1 Like

Yes, those scripts are adding every unimodule that is in node_modules. The recommended way to minimize number of packages like that is to make sure that they are not present in node_modules.

Okay thats really good to know. I had assumed that by adding it to exclude it would also be excluded from node_modules but it really is still there.

Do you usually delete in the post-install script for package.json?
Do you have any examples you can link me to?

I also made a request for documentation on how to keep the bundle size small. Imo its table stakes for getting the bare expo workflow to be used by larger production apps.

OK based on what you posted on github i now know what you wanted to achive.

Just to clarify few things

  • exclude option was added because we needed it internally, (it can be used be everyone but it should not necessary)
  • if you don’t want some module to be included just don’t install it
  • unimodules that are present in node_modules, but they were not installed by you are all required, you should not exclude them. It might work for you, but might break in certain cases or in the future after some changes.

Optimization like that won’t improve your app size, most of the unimodules are very small (maybe except face detector). Main part of archive size is JSC and react-native, on android minimal apk/aab you can have is sth around 10 MB

If you don’t use expo package directly you might want to remove it, there are some dependecies there that might be unnecesary.
My previous point was about react-native-unimodules, dependencies of that package should always be included

see this answer on forums for more info https://github.com/expo/expo/issues/9736#issuecomment-674225903