Bomber
Bomber

Reputation: 10967

Share react native components across repos

I have three react native projects each with their own repo.

They use very similar components, is there a way I can share these components across repo's, so I don't have to update each repo independently?

Or can I create three different apps, from one repo? with only very slight changes to images and configs for each app.

Upvotes: 2

Views: 385

Answers (2)

MJ Studio
MJ Studio

Reputation: 4631

Solution 1: Separated npm package

In my project, I separated my core parts with each npm package.

  1. Create npm package and put your shared components into that.
  2. You can test immediately your shared component's function with npm link or specify your local package's absolute path with npm install.
  3. If you want to manage your package more intuitive way, then you can publish your package to npm repository with private mode.

Solution 2: Depend on the environment variable

You can separate your running environment with react-native-config. With this package, created multiple environments .env or .env.production you can separate your runtime variables with ENVFILE=.env npm start or ENVFILE=.env.production npm start. Then in your javascript code, you can refer your each runtime settings.

import Config from 'react-native-config';

const isProduction = Config.environment === 'production';

<Image source={isProduction ? require(..production_image) : require(..development_image)} />

How to show your slight difference in your app depends on you. like Platform.os === 'ios'

Upvotes: 2

Vinit Bhavsar
Vinit Bhavsar

Reputation: 252

Refere this: https://github.com/luggit/react-native-config

You can create different builds : Production, staging, testing.

You can set multiple environment and generate build.

Upvotes: 0

Related Questions