如何在package.json中使用环境变量 [英] How to use environment variables in package.json

查看:762
本文介绍了如何在package.json中使用环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我们不希望项目代码中的敏感数据,包括package.json文件,使用环境变量在我看来是一个合理的选择.

Because we don't want sensitive data in the project code, including the package.json file, using environment variables would be a logical choice in my opinion.

示例package.json:

Example package.json:

  "dependencies": {
    "accounting": "~0.4.0",
    "async": "~1.4.2",
    "my-private-module":"git+https://${BB_USER}:${BB_PASS}@bitbucket.org/foo/bar.git"

这可能吗?

(如果这是明智不好,那么问题是不是,如果可能,只是 )

(The question is not if this is wise or not good, just if it's possible)

致谢!

我.

推荐答案

我有类似但不同的要求.对我来说,我想在脚本中使用环境变量.

I have similar but different requirement. For me, I want to use environment variables in the scripts.

我不是直接在package.json中使用环境变量,而是这样做:

Instead of using the environment variables directly in package.json, I do:

"some-script": "./scripts/some-script.sh",

在some-script.sh中:

And in some-script.sh:

#!/bin/sh

npm run some-other-script -- --prop=$SOME_ENV_VAR

这篇关于如何在package.json中使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆