小编cal*_*ity的帖子

如何在 npm 中使用 package.json 依赖项的(环境)变量?

在 npm 中,我希望能够从私有 GitHub 存储库安装包作为依赖项,而git+https不必对实际的进行硬编码github_username:personal_access_token,而是将它们作为(环境)变量插入依赖项字符串中。

所以而不是

package.json:

...
"dependencies": {
  ...
  "my-private-github-repo": "git+https://<github_username>:<personal_access_token>@github.com/some/package.git",
  ...
}
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

package.json:

...
"dependencies": {
  ...
  "my-private-github-repo": "git+https://${github_username}:${personal_access_token}@github.com/some/package.git",
  ...
}
Run Code Online (Sandbox Code Playgroud)

在应用我希望能够执行的版本控制 时,硬编码凭据是一个主要禁忌。package.json

做这个的最好方式是什么?

github environment-variables npm package.json npm-install

5
推荐指数
1
解决办法
6642
查看次数