How to use environment variables in package.json

后端 未结 6 1785
有刺的猬
有刺的猬 2020-12-30 19:01

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.

Exam

6条回答
  •  天命终不由人
    2020-12-30 19:23

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

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

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

    And in some-script.sh:

    #!/bin/sh
    
    npm run some-other-script -- --prop=$SOME_ENV_VAR
    

提交回复
热议问题