Skip to content

Instantly share code, notes, and snippets.

@beata
Last active April 13, 2018 07:39
Show Gist options
  • Save beata/aa7e6e4c088416f73d6c956717133917 to your computer and use it in GitHub Desktop.
Save beata/aa7e6e4c088416f73d6c956717133917 to your computer and use it in GitHub Desktop.
Require module defined in react-native-config
# rn-cli.config.js
const fs = require('fs');
const ini = require('ini');
const path = require('path');
let config = {};
if (process.env.ENVFILE) {
config = ini.parse(fs.readFileSync(path.resolve(__dirname, process.env.ENVFILE), 'utf-8'));
}
module.exports = {
extraNodeModules: {
'APP_THEME': path.resolve(__dirname, 'src/themes/' + config.APP_THEME)
},
};
# src/Root.js
import theme from 'APP_THEME'; // extraNodeModule defined in `rn-cli.config.js`
class Root extends Component {
store = getStore()
render() {
return (
<Provider store={this.store}>
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
</Provider>
);
}
}
export default Root;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment