New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding envFile argument in nx serve / build for custom env loading #7729
Comments
I think also grabbing the That way we can manage custom configurations (which is usually typical for dev/staging/prod etc.) and add |
Any Update on this ? |
I am having the same issue. |
+1 for this |
Can't believe other executor doesn't support this |
+1 for this @FrozenPandaz from the Jane tech crew and iheartjane.com. We would be happy to put a PR together if that would help. We also use the cascade loading method, so we may have a local Our {
"build": "dotenv -c development -- nx run-many --target=build --all --parallel=3",
} It would be lovely if we could add an env specific configuration to the "configurations": {
"development": {
"envFiles": [
".env.development",
".env.development.local"
]
}, Then we can update our {
"build": "nx run-many --target=build --all --parallel=3 --configuration=development",
} |
@ShadabFaiz +1 it works |
I would love to have what @wesleygrimes propose ! |
Here's an example of laravel's artisan command and it's syntax is https://laravel.com/docs/9.x/configuration#additional-environment-files This is a very very helpful feature for development, especially if you need to target multiple environments and you don't want to pollute your codebase with that kind of configuration. |
+1 |
2 similar comments
+1 |
+1 |
This is an absolutely vital feature in my opinion. Without the ability to configure .env files in each Nx target's |
+1 |
+1 in support of @wesleygrimes suggestion |
Glad everyone seems to agree, any thoughts or plans to implement something like this @FrozenPandaz? |
Is there any way to ignore (context: lerna/lerna#3371) |
@tschaffter luckily, they were kind enough to (very quickly!) add an option to disable this in #12602! Some more context in the thread mentioned earlier. |
Is there a plan to support |
Was following the guides:
And running into the same problem. Use Case:
I configured:
How can we accomplish this without doing something like this? "serve": {
"executor": "@nrwl/angular:webpack-dev-server",
"configurations": {
"production": {
"browserTarget": "movie-db:build:production"
},
"development": {
"browserTarget": "movie-db:build:development"
}
},
"defaultConfiguration": "development"
},
/// THIS IS/FEELS PRETTY REDUNDANT
"mock": {
"executor": "@nrwl/angular:webpack-dev-server",
"configurations": {
"mock": {
"browserTarget": "movie-db:build:development"
}
},
"defaultConfiguration": "mock"
},
Would really prefer something like this: "serve": {
"executor": "@nrwl/angular:webpack-dev-server",
"configurations": {
"production": {
"browserTarget": "movie-db:build:production"
},
"development": {
"browserTarget": "movie-db:build:development"
},
"mock": { // ADD extra target.. or even better -> envFile argument
"browserTarget": "movie-db:build:development"
}
},
"defaultConfiguration": "development"
},
And a |
Was there an update on this? This is especially relevent when using NextAuth in multiple apps in NX. NEXTAUTH_URL is different for each app and loading them at runtime for different configurations (dev/stg/prod) would be super helpful |
+1 looking for this functionality too @wesleygrimes suggestion seems suitable |
Also looking for a solution to this. Can we in the meantime use the solution posted here? Where we just swap the .env file when using a certain configuration. |
For anyone still having issue with this: |
For anyone looking to use different env files per configuration. A new feat has recently been merged to allow this (#14998) |
I'm going to close this out. I think the configuration based env files should hit 98% of the use cases, since you'd be specifying the custom env file within a configuration either way. If anyone has use cases which are not covered by #14998, or has issues after the release of 15.8.0 on this matter, feel free to open a new issue. |
So to be clear, if I want to run |
You would have a configuration for dev / staging defined in the serve target, and run |
Not exactly true, as in this case you would need to define I'm currently solving a problem defining different whitelabel variables, and this can quickly become unreadable (imagine 5 whitelabels, each having to define build, serve and build-docker targets). So a workaround could be wrapping those executors (NextJs specific) into custom executors, where based on a schema value (whitelabel value), an ENV variable is set dynamically. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Description
https://nx.dev/l/r/guides/environment-variables#pointing-to-custom-env-files
As per the documentation part above if I need to load custom env files for
nx serve
i need to useenv-cmd -f .qa.env nx serve
.When running it as a single command was ok. But mostly that's not the case we have more than 1 app to serve for development thus use
nx run-many --target=serve --all --parallel --maxParallel=10
. In that case, we cannot use the custom envs.For
@nrwl/workspace:run-commands
has an argument likeenvFile
if we can pass similarly as part of configuration then the whole process will get simplified.Motivation
We are using different envs for different environments like
.env.development
for local,.env.staging
for staging, and likewise. For next projects(https://nx.dev/l/r/next/overview), these files are working but not for react projects(https://nx.dev/l/r/react/overview). So currently we need to manually copy and paste.env.development
to.env
. Currently we are using a make file to do the work but if we have it in workspace.json -> app -> configurations then we don't need to depend on the make fileSuggested Implementation
Add an additional argument
envFile
for react serve command (https://nx.dev/l/r/web/dev-server) and all the other app generators like nest, next, node, etc.Alternate Implementations
No alternative I could think of or we can only do hacks to solve the issue
The text was updated successfully, but these errors were encountered: