npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

config-by-env

v0.1.0

Published

Easily create configs for different environments

Downloads

4

Readme

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.