Code Monkey home page Code Monkey logo

envcmd-record's Introduction

dev prod test 環境配置

安裝相關的 Plugin

yarn add env-cmd

HELP Usage

Options:
  -v, --version                       output the version number
  -e, --environments [env1,env2,...]  The rc file environment(s) to use
  -f, --file [path]                   Custom env file path (default path: ./.env)
  --fallback                          Fallback to default env file path, if custom env file path not found
  --no-override                       Do not override existing environment variables
  -r, --rc-file [path]                Custom rc file path (default path: ./.env-cmdrc(|.js|.json)
  --silent                            Ignore any env-cmd errors and only fail on executed program failure.
  --use-shell                         Execute the command in a new shell with the given environment
  --verbose                           Print helpful debugging information
  -x, --expand-envs                   Replace $var in args and command with environment variables
  -h, --help                          output usage information 

package.json 相關配置

env-file
├─.env-dev.env # dev env 檔
├─.env-prod.env # dev env 檔
├─.env-test.env # dev env 檔
├─index.js  #入口
├─package.json
└yarn.lock

建立好相關的檔案 dev 檔及內容

嗨客网

TEST_NAME=Default File Path prod
NODE_ENV=prod
ENVVAR=exists
ENV_PATH=./.env-prod.env

執行情況

hudoudou@hudoudoudeMacBook-Pro env-file % yarn prod
 #當執行後將會自動在package.json 運行script相關的命令行
yarn run v1.22.15
warning package.json: No license field
warning ../../../../../package.json: No license field
$ env-cmd --verbose -f .env-prod.env node index.js #<-----這裏運行
Options: {"command":"node","commandArgs":["index.js"],"envFile":{"filePath":".env-prod.env"},"options":{"expandEnvs":false,"noOverride":false,"silent":false,"useShell":false,"verbose":true}}
Found .env file at path: .env-prod.env
[
  '/Users/hudoudou/.nvm/versions/node/v16.15.0/bin/node',
  '/Users/hudoudou/Desktop/recode/ENVCMD/env-cmd-examples/examples/env-file/index.js'
]
#這裏是我在Index.js 運行log的情況
Environment---> prod  #對應dev內容輸出
ENVVAR---> exists #對應dev內容輸出
ENV_PATH---> ./.env-prod.env #對應dev內容輸出
Child process exited with code: 0 and signal:. Terminating parent process...
✨  Done in 0.12s.

envcmd-record's People

Contributors

hanboylee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.