I have three environments (local, test and prod) in my NodeJS based server project in my nx workspace. I require three different environment.ts
files.
I have the following configuration in my workspace.json
for my NodeJS project:
"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"
}
]
}
}
},
The environment files sit in the same hierarchy:
I am unable to find which command will pick up the test
configuration. I have tried multiple things it did not work:
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
Expected Behavior
I should be able to choose between different environment files during the build.
Current Behavior
fileReplacement
does not seem to work for NodeJS project for anything other than prod
.
Steps to Reproduce
In your workspace with one server side project, say api, do the the following:
1. Add a new file environment.test.ts
on the same pattern as the existing environment.prod.ts
2. In the workspace.json
under the "api" > "architect" > "buiid" > "configurations"
block, add a new configuration for the "test" environment that looks like the existing "production" configuration, except it has "fileReplacements"
array that looks like this:
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
Now try to do a build that picks up and replaces environment.ts with environment.test.ts during the build. It does not seem to be possible.
The commands I tried above did not help me. Here is my nx version.
nx --version
8.9.0
- Relevant issue I raised here: https://github.com/nrwl/nx/issues/2870
- Similar concerns were raised here: Using environment variables in nx based nodejs app