An extension to add a web support for react-native-config package. This package is based on react-web-config from tanhauhau.
Install react-native-config
according to its manual.
Install @kleinstein/react-web-config
:
- NPM:
npm install @kleinstein/react-web-config
- Or Yarn:
yarn add @kleinstein/react-web-config
Add next lines to webpack.config.js
:
const path = require('path');
const webpack = require('webpack');
+ const webConfig = require('@kleinstein/react-web-config/WebConfig');
...
+ // Replace '.env' by actual filename
+ const envPath = path.resolve(__dirname, '.env');
...
module.exports = {
...
resolve: {
...
alias: {
...
+ 'react-native-config': '@kleinstein/react-web-config',
},
...
},
...
plugins: [
...
new webpack.DefinePlugin({
...
+ __REACT_WEB_CONFIG__: JSON.stringify(webConfig(envPath)),
}),
...
],
...
};
.env:
HELLO_WORLD="Hello, World!"
In code:
import Config from 'react-native-config'
...
Config.HELLO_WORLD
Project is licensed under the MIT license. See LICENSE for the full license text.