对于非本地、非生产环境的 NodeJS 项目,nwrl nx 环境文件不会被替换
nwrl nx environment files is not replaced for NodeJS project for non-local, non-prod environments
我在 nx 工作区的基于 NodeJS 的服务器项目中有三个环境(本地、测试和生产环境)。我需要三个不同的 environment.ts
文件。
我的 NodeJS 项目 workspace.json
中有以下配置:
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.prod.ts"
}
]
},
"test": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
]
}
}
},
环境文件位于同一层次结构中:
我找不到哪个命令会选择 test
配置。我试过很多东西都没有用:
nx build api --test # does not work
NODE_ENV=test nx build api # does not work
NODE_ENV=test nx build api --test # does not work
nx build api -c=test # does not work
nx build api -c test # does not work
nx build api --prod # works for prod env file
预期行为
我应该可以在构建过程中选择不同的环境文件。
当前行为
fileReplacement
似乎不适用于 NodeJS 项目,除了 prod
.
重现步骤
在有一个服务器端项目的工作区中,假设 api,执行以下操作:
1. 在与现有 environment.prod.ts
相同的模式上添加新文件 environment.test.ts
2. 在 "api" > "architect" > "buiid" > "configurations"
块下的 workspace.json
中,为 "test" 环境添加一个新的配置,看起来像现有的 "production" 配置,除了它有 "fileReplacements"
看起来像这样的数组:
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
现在尝试进行构建,在构建过程中将 environment.ts 替换为 environment.test.ts。这似乎是不可能的。
我上面尝试的命令没有帮助我。这是我的 nx 版本。
nx --version
8.9.0
- 我在这里提出的相关问题:https://github.com/nrwl/nx/issues/2870
- 这里提出了类似的问题:
指令为nx build api --configuration=test
或nx build api --c=test
如果您使用的是 Nx Console VS Code 插件,您可以 select 构建菜单下顶部的选项之一。结果命令与上面提到的完全相同。为清楚起见,这里是屏幕截图。
我在 nx 工作区的基于 NodeJS 的服务器项目中有三个环境(本地、测试和生产环境)。我需要三个不同的 environment.ts
文件。
我的 NodeJS 项目 workspace.json
中有以下配置:
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.prod.ts"
}
]
},
"test": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
]
}
}
},
环境文件位于同一层次结构中:
我找不到哪个命令会选择 test
配置。我试过很多东西都没有用:
nx build api --test # does not work
NODE_ENV=test nx build api # does not work
NODE_ENV=test nx build api --test # does not work
nx build api -c=test # does not work
nx build api -c test # does not work
nx build api --prod # works for prod env file
预期行为
我应该可以在构建过程中选择不同的环境文件。
当前行为
fileReplacement
似乎不适用于 NodeJS 项目,除了 prod
.
重现步骤
在有一个服务器端项目的工作区中,假设 api,执行以下操作:
1. 在与现有 environment.prod.ts
相同的模式上添加新文件 environment.test.ts
2. 在 "api" > "architect" > "buiid" > "configurations"
块下的 workspace.json
中,为 "test" 环境添加一个新的配置,看起来像现有的 "production" 配置,除了它有 "fileReplacements"
看起来像这样的数组:
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
现在尝试进行构建,在构建过程中将 environment.ts 替换为 environment.test.ts。这似乎是不可能的。
我上面尝试的命令没有帮助我。这是我的 nx 版本。
nx --version
8.9.0
- 我在这里提出的相关问题:https://github.com/nrwl/nx/issues/2870
- 这里提出了类似的问题:
指令为nx build api --configuration=test
或nx build api --c=test
如果您使用的是 Nx Console VS Code 插件,您可以 select 构建菜单下顶部的选项之一。结果命令与上面提到的完全相同。为清楚起见,这里是屏幕截图。