https://github.com/ericclemmons/if-env
Simplify npm scripts with `if-env ... && npm run this || npm run that`
https://github.com/ericclemmons/if-env
Last synced: about 1 year ago
JSON representation
Simplify npm scripts with `if-env ... && npm run this || npm run that`
- Host: GitHub
- URL: https://github.com/ericclemmons/if-env
- Owner: ericclemmons
- License: mit
- Created: 2015-12-23T03:46:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-11-22T10:39:15.000Z (over 5 years ago)
- Last Synced: 2025-04-02T06:07:50.131Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 97
- Watchers: 3
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# if-env
> Simplify npm scripts with `if-env ... && npm run this || npm run that`
- - -
**I recommend switching to [`per-env`](https://github.com/ericclemmons/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:
```json
"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:
```json
"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
```shell
$ npm install if-env --save
```
### 2. Add to `package.json`
```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