https://github.com/kentcdodds/argv-set-env
Set environment variables in npm scripts
https://github.com/kentcdodds/argv-set-env
Last synced: about 1 year ago
JSON representation
Set environment variables in npm scripts
- Host: GitHub
- URL: https://github.com/kentcdodds/argv-set-env
- Owner: kentcdodds
- Created: 2015-10-20T21:50:48.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2021-01-25T23:22:41.000Z (over 5 years ago)
- Last Synced: 2025-06-20T02:24:05.327Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://tonicdev.com/npm/argv-set-env
- Size: 4.88 KB
- Stars: 51
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.json
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
You might actually want to look at my other utility [cross-env](http://npm.im/cross-env). It's probably what you're really looking for :-)
# argv-set-env
Status:
[](https://www.npmjs.org/package/argv-set-env)
[](http://npm-stat.com/charts.html?package=argv-set-env&from=2015-09-01)
[](https://travis-ci.org/kentcdodds/argv-set-env)
[](https://codecov.io/github/kentcdodds/argv-set-env)
[](https://github.com/feross/standard)
Use in your config files to set environment variables cross-platform.
## Usage
I use this with my npm scripts:
```javascript
{
"scripts": {
"build": "webpack --set-env-NODE_ENV=production",
"test": "karma start --set-env-COVERAGE=true --set-env-NODE_ENV=test"
}
}
```
And then in my `webpack.config.js` file, at the very top I do:
```javascript
require('argv-set-env')()
```
Which in the case of `build` would set `NODE_ENV` to the string `'production'` and in the case of
`test` it would set `NODE_ENV` to the string `'test'` and `COVERAGE` to the boolean `true`.
### Options
You can optionally pass `options`:
```javascript
require('argv-set-env')({
// I'm setting these to the defaults here
// you could set them to whatever you want
env: process.env, // the object to have variables set on
argv: process.argv, // the array of arguments which have the arguments defined
prefix: '--set-env', // the prefix used in the array of arguments defining variables to set
})
```
## LICENSE
MIT