Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kentcdodds/argv-set-env
Set environment variables in npm scripts
https://github.com/kentcdodds/argv-set-env
Last synced: 3 months 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 (over 8 years ago)
- Default Branch: main
- Last Pushed: 2021-01-25T23:22:41.000Z (over 3 years ago)
- Last Synced: 2024-03-18T16:16:29.259Z (3 months ago)
- Language: JavaScript
- Homepage: https://tonicdev.com/npm/argv-set-env
- Size: 4.88 KB
- Stars: 52
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.json
- Code of conduct: CODE_OF_CONDUCT.md
Lists
- awesome-nodejs-cross-platform-cli - argv-set-env - Set environment variables. e.g. `webpack --set-env-NODE_ENV=production`. (Packages)
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:
[![npm version](https://img.shields.io/npm/v/argv-set-env.svg?style=flat-square)](https://www.npmjs.org/package/argv-set-env)
[![npm downloads](https://img.shields.io/npm/dm/argv-set-env.svg?style=flat-square)](http://npm-stat.com/charts.html?package=argv-set-env&from=2015-09-01)
[![Build Status](https://img.shields.io/travis/kentcdodds/argv-set-env.svg?style=flat-square)](https://travis-ci.org/kentcdodds/argv-set-env)
[![Code Coverage](https://img.shields.io/codecov/c/github/kentcdodds/argv-set-env.svg?style=flat-square)](https://codecov.io/github/kentcdodds/argv-set-env)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](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