後來我研究了一下 package.json 裡定義的腳本:發現使用了 env-cmd 這個工具:
env-cmd --no-override -e dev,b2c,$SPA_ENV ng serve
env-cmd 的作用:A simple node program for executing commands using an environment from an env file.
For more complex projects, a .env-cmdrc file can be defined in the root directory and supports as many environments as you want. Simply use the -e flag and provide which environments you wish to use from the .env-cmdrc file.
在項目的根目錄下,放置一個名為 .env-cmdrc 的檔案,然後使用 -e 标簽,指定需要使用 env-cmdrc 檔案裡定義的哪個 environments 去運作腳本。
Using multiple environment names will merge the environment variables together. Later environments overwrite earlier ones in the list if conflicting environment variables are found.
如果 -e 後面跟了多個環境名,則每個環境名裡包含的變量值,會被 merge 成一個整體。 如果兩個環境裡都包含了同樣的變量值,則後出現的環境的變量值會覆寫先前的環境變量值。
set CX_B2B=true && set CX_BASE_URL=https://spartacus-dev0.azure.com:9002 && yarn start