简体   繁体   中英

Pass more than one variable to a package.json script

I have in package.json (NOT BASH, NOT SH, NOT ZSHELL, NOT FISH).

So after we established the fact that this is my package.json file, let me present it to you:

package.json

  "scripts": {
    "dev": "NODE_ENV=myValue myProgram"
  }

I want to add more vars (eg MYVAR=myOtherValue ) to above file, which is my package.json file. How can I do that (adding more vars to my package.json file)?

Let me be clear that I do not want to read the manpage of bash or zshell, or fish, or sh. This is why I put the question in here and did not read the manpage - otherwise I would not put it here and would have read the manpage. Thank you for understanding.

Your script should be:

"dev": "NODE_ENV=myValue MYVAR=myOtherValue myProgram"

as you can multiple environments when space-separated. This stems from the common behavior from terminals like bash, where you can set multiple env variables on the fly:

FOO1=baz FOO2=fnord FOO3=baz env | grep FOO
FOO1=baz
FOO2=fnord
FOO3=baz

I am with Stevek on this one, I read the answer (the duplicate answer) and am frustrated with the references to bash. I am on a windows system that uses Powershell. I want to pass multiple environmental variables and have it work in windows systems using Powershell. Any reference to *nix commands etc unless to enable cross-system use is mudding the waters.

So far this answer is not answered. So will add what I found

This questions tells you how to pass 1 variable. How to set environment variables from within package.json

 "start": "set NODE_ENV=YOURENV&&node start.js"

Now how to pass more than 1? That is still the question.

I was told that using cross-env is the best: cross-env NODE_ENV=production my-command

The answer was given here: https://github.com/kentcdodds/cross-env/issues/15

"scripts": {
  "debug": "cross-env NODE_PATH=. DEBUG=app:* nodemon bootload.js"
}

However, cross-env does not use PowerShell but depreciate cmd shell on windows. So back to the main issue. [unless you make this change https://github.com/kentcdodds/cross-env/issues/192#issuecomment-513341729]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM