if-env-defined

1.0.0 • Public • Published

if-env-defined

Forked from if-env

Simplify npm scripts with if-env-defined ... && npm run this || npm run that


Suppose you want to simplify development and be able to run npm start in all environments & run the correct scripts.

Your package.json might look like this:

"scripts"{
  "start": "if [[ -z ${NODE_ENV} ]]; then npm run start:prod; else npm run start:dev; fi",
  "start:dev": "webpack",
  "start:prod": "start-cluster"
}

The problem is, this doesn't work in all environments.

Instead, you can write:

"scripts"{
  "start": "if-env-defined NODE_ENV && npm run start:prod || npm run start:dev",
  "start:dev": "webpack",
  "start:prod": "start-cluster"
}

Usage

1. Install

$ npm install if-env-defined --save

2. Add to package.json

"scripts"{
  "start": "if-env-defined SOME_ENV_VAR=some_val ANOTHER_ENV_VAR=another_val && npm run this || npm run that"
}

License

MIT © Eric Clemmons 2015

/if-env-defined/

    Package Sidebar

    Install

    npm i if-env-defined

    Weekly Downloads

    2,387

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.75 kB

    Total Files

    6

    Last publish

    Collaborators

    • pr00f