Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
docs(README): added how to use cross-env to run npm sub-scripts (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 authored and Kent C. Dodds committed Feb 3, 2017
1 parent afdb2de commit 5e590ec
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,19 @@ webpack --config build/webpack.config.js

The `NODE_ENV` environment variable will be set by `cross-env`

You can also split a command into several ones, or separate the environment variables declaration from the actual command execution. You can do it this way:

```json
{
"scripts": {
   "parentScript": "cross-env GREET='Joe' npm run childScript",
"childScript": "echo Hello $GEET"
}
}
```

Where `childScript` holds the actual command to execute and `parentScript` sets the environment variables to use.
Then instead of run the childScript you run the parent. This is quite useful for launching the same command with different env variables or when the environment variables are too long to have everything in one line.

## Why?

Expand All @@ -58,6 +71,8 @@ And expect it to output `bar` you're going to be sad, for two reasons:
The main use case for this package is to simply run another script which will (itself) respond to the environment
variable. These limitations are not a problem in that scenario (like in the example).

If you want to modularize your npm scripts take a look at the proposed solution on the usage section.

## Related Projects

[`env-cmd`](https://github.com/toddbluhm/env-cmd) - Reads environment variables from a file instead
Expand Down

0 comments on commit 5e590ec

Please sign in to comment.