@kleinstein/react-web-config

1.0.0 • Public • Published

@kleinstein/react-web-config

npm version license

Overview

An extension to add a web support for react-native-config package. This package is based on react-web-config from tanhauhau.

Installation

Step 1:

Install react-native-config according to its manual.

Step 2:

Install @kleinstein/react-web-config:

  • NPM: npm install @kleinstein/react-web-config
  • Or Yarn: yarn add @kleinstein/react-web-config

Step 3:

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)),
      }),
      ...
    ],
    ...
  };

Usage

.env:

HELLO_WORLD="Hello, World!"

In code:

import Config from 'react-native-config'
...
Config.HELLO_WORLD

Licensing

Project is licensed under the MIT license. See LICENSE for the full license text.

Package Sidebar

Install

npm i @kleinstein/react-web-config

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

4.8 kB

Total Files

10

Last publish

Collaborators

  • ghostman