Sometimes I need to run my react native app with different App.js
file, lets call it App2.js
.
I’m modifying index.js
manually.
import { AppRegistry } from 'react-native'
//const myApp = require('./src/App2').default
const myApp = require('./src/App').default
AppRegistry.registerComponent('Dummy app, () => myApp)
Is it possible to add script to package.json for this?
Something like react-native start:app2
or in different way.
I looked to react native cli documentation and start
command doesn’t have anything similar. Only --projectRoot
which is not really what I’m looking for.
2
Answers
Open your package.json file.
Add a new script entry with a custom name, such as "start:app2", and set its value to the command you want to execute. In this case, it will be the modified index.js file that imports App2.js. Your updated package.json script section should look like this:
You can use react-native-dotenv.
npm install --save react-native-dotenv
Config should be:
index.js
finally on package.json
Please note that reset cache option is required.