1. if-env
Simplify npm scripts with "if-env ... && npm run this || npm run that"
if-env
Package: if-env
Created by: ericclemmons
Last modified: Sun, 19 Jun 2022 00:15:09 GMT
Version: 1.0.4
License: MIT
Downloads: 120,556
Repository: https://github.com/ericclemmons/if-env

Install

npm install if-env
yarn add if-env

if-env

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


I recommend switching to per-env, which is much simpler and much more powerful!


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 [[ ${NODE_ENV} == \"production\" ]]; 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 NODE_ENV=production && npm run start:prod || npm run start:dev",
  "start:dev": "webpack",
  "start:prod": "start-cluster"
}

Usage

1. Install

 $ npm install if-env --save

2. Add to package.json

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

License

MIT © Eric Clemmons 2015

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code