使用来自 package.json 的环境变量运行 npm 脚本



我正在使用一个特定的任务运行器来执行名为 Yoshi 的节点脚本。我想从package.json运行脚本,例如,yoshi test但使用自定义环境变量(例如special_variable(:

"scripts": {
"start": "yoshi start", 
"test":  "special_variable=value yoshi test // this case"
}

显然,我可以在我的npm-script中使用ENV前缀传递一个环境变量,如下所示:

"scripts": {
"start": "yoshi start", 
"test":  "ENV special_variable=value yoshi test"
}

我认为您可以创建.env文件并在那里添加变量。

最新更新