diff --git a/docs/shared/guides/define-environment-variables.md b/docs/shared/guides/define-environment-variables.md index 97c4a2ffdd..7f9f33e117 100644 --- a/docs/shared/guides/define-environment-variables.md +++ b/docs/shared/guides/define-environment-variables.md @@ -9,16 +9,20 @@ the runtime of an app. By default, Nx will load any environment variables you place in the following files: -1. `apps/my-app/.[target-name].env` -2. `apps/my-app/.env.[target-name]` -3. `apps/my-app/.local.env` -4. `apps/my-app/.env.local` -5. `apps/my-app/.env` -6. `.[target-name].env` -7. `.env.[target-name]` -8. `.local.env` -9. `.env.local` -10. `.env` +1. `apps/my-app/.env.[target-name].[configuration-name]` +2. `apps/my-app/.[target-name].[configuration-name].env` +3. `apps/my-app/.env.[target-name]` +4. `apps/my-app/.[target-name].env` +5. `apps/my-app/.env.local` +6. `apps/my-app/.local.env` +7. `apps/my-app/.env` +8. `.env.[target-name].[configuration-name]` +9. `.[target-name].[configuration-name].env` +10. `.env.[target-name]` +11. `.[target-name].env` +12. `.local.env` +13. `.env.local` +14. `.env` {% callout type="warning" title="Order is important" %} Nx will move through the above list, ignoring files it can't find, and loading environment variables diff --git a/packages/nx/src/tasks-runner/forked-process-task-runner.ts b/packages/nx/src/tasks-runner/forked-process-task-runner.ts index b39c061807..663f540c9a 100644 --- a/packages/nx/src/tasks-runner/forked-process-task-runner.ts +++ b/packages/nx/src/tasks-runner/forked-process-task-runner.ts @@ -385,11 +385,27 @@ export class ForkedProcessTaskRunner { ...this.getDotenvVariablesForForkedProcess(), ...parseEnv(`.${task.target.target}.env`), ...parseEnv(`.env.${task.target.target}`), + ...(task.target.configuration + ? parseEnv(`.${task.target.target}.${task.target.configuration}.env`) + : {}), + ...(task.target.configuration + ? parseEnv(`.env.${task.target.target}.${task.target.configuration}`) + : {}), ...parseEnv(`${task.projectRoot}/.env`), ...parseEnv(`${task.projectRoot}/.local.env`), ...parseEnv(`${task.projectRoot}/.env.local`), ...parseEnv(`${task.projectRoot}/.${task.target.target}.env`), ...parseEnv(`${task.projectRoot}/.env.${task.target.target}`), + ...(task.target.configuration + ? parseEnv( + `${task.projectRoot}/.${task.target.target}.${task.target.configuration}.env` + ) + : {}), + ...(task.target.configuration + ? parseEnv( + `${task.projectRoot}/.env.${task.target.target}.${task.target.configuration}` + ) + : {}), }; } else { return {};