Run scripts that set and use environment variables across platforms
譯文:運作跨平台設定和使用環境變量的腳本
安裝
npm
{
"scripts": {
"test": "cross-env NODE_ENV=production node test.js",
},
"devDependencies": {
"cross-env": "^7.0.3",
},
}
# 直接運作,NODE_ENV是undefined
$ node test.js
undefined
# 運作腳本前設定環境變量
$ npx cross-env NODE_ENV=production node test.js
production
# 使用scripts
$ npm run test
> test
> cross-env NODE_ENV=production node