后来我研究了一下 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