Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I handling correctly multiple projects with a common code base?

Tags:

react-native

I am creating several mobile applications in react-native that share common components. I have difficulties handling the dependencies. Here is what I do, which is tedious, is there a better way?

  • A repository "common-modules" has shared components
  • Several repositories include the common one as a dependency like this:

Package.json

"dependencies": {
    "common-components": "file:../common-components"
},

I use it like that in the different apps:

import XXX from 'common-components/src/...'

Now this is great because all other dependencies are in "common-components", but as soon as one of them has native code, I am forced to link the library again in each app.

For instance, if I use "react-native-image-picker", I have to install it again in each application and link it in XCode, edit build.gradle etc. etc.

  • It takes forever
  • Are my linked dependencies bundled twice?
  • I fear the day when I must change/upgrade one of them...

Is there a better way?

like image 865
JulienD Avatar asked Jun 01 '18 14:06

JulienD


1 Answers

I've heard of projects that share code being managed in a monorepo. That may help managing shared code but won't solve the problem of linking native modules N times for N apps.

However, there is react-native link that should automate the process, and ease linking the native modules a lot. Note there is no need to re-link if you just upgrade a native dependency.

Alternatively, I think it should be possible to wrap multiple native modules into one. If you take a look at MainReactPackage.java in RN repo, it wraps several native modules. I imagine similar mechanism can be employed on iOS, with static libraries. Obviously, this means that it won't be easy to selectively include some modules and others not.

like image 93
vonovak Avatar answered Oct 05 '22 23:10

vonovak