Socket
Socket
Sign inDemoInstall

config-by-env

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    config-by-env

Easily create configs for different environments


Version published
Maintainers
1
Install size
8.30 kB
Created

Readme

Source

config-by-env

Build Status npm

Create a config from an object of configs, based on the current environment. The configs matching the environment will be merged together. A common config can be defined, which will be used as the base config.

Usage

const configByEnv = require('config-by-env');

const configs = {
  common: {
    plugins: ['transform-async-to-generator', 'transform-jsx']
  },
  production: {
    plugins: ['transform-react-remove-prop-types']
  }
};

module.exports = configByEnv(configs);

The result depends on the value of NODE_ENV. In this case it will always use the common config as a base, but running with NODE_ENV=production will merge the production config with common.

// Regular (any NODE_ENV except production)
{
  plugins: ['transform-async-to-generator', 'transform-jsx']
}

// NODE_ENV=production
{
  plugins: [
    'transform-async-to-generator',
    'transform-jsx',
    'transform-react-remove-prop-types'
  ]
}

The environment variable CONFIG_BY_ENV can also be used to define the environment. It takes precedence over NODE_ENV. You might want to use a different config from NODE_ENV, especially since multiple values are allowed by separating them with commas and this could mess up anything else that depends on it being a single value.

# Uses the production and the react config, could mess up tools building for production.
NODE_ENV=production,react

# Builds for production but only uses the react config.
NODE_ENV=production CONFIG_BY_ENV=react

When neither CONFIG_BY_ENV nor NODE_ENV is set, it defaults to development.

API

configByEnv(configs, [options])

Creates a config by merging the ones from configs that match the environment.

options

createArray (default: true)

When it's set to true any property that is defined on two configs, being merged together, it will automatically combine the two into an array, unless both are an object, in which case they are deeply merged as well. When it's set to false it will overwrite the value.

const configs = {
  common: { a: 1 },
  development: { a: 2 }
};
configByEnv(configs) // { a: [1, 2] }
configByEnv(configs, { createArray: false }) // { a: 2 }

shallow (default: false)

Use either a shallow or a deep merge.

skipCommon (default: false)

Do not use the common config as a base when set to true.

Keywords

FAQs

Last updated on 28 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc