feat(core): allow loading env vars by target and configuration (#14998)
This commit is contained in:
parent
d7c8e03b5e
commit
24e87e6cc4
@ -9,16 +9,20 @@ the runtime of an app.
|
|||||||
|
|
||||||
By default, Nx will load any environment variables you place in the following files:
|
By default, Nx will load any environment variables you place in the following files:
|
||||||
|
|
||||||
1. `apps/my-app/.[target-name].env`
|
1. `apps/my-app/.env.[target-name].[configuration-name]`
|
||||||
2. `apps/my-app/.env.[target-name]`
|
2. `apps/my-app/.[target-name].[configuration-name].env`
|
||||||
3. `apps/my-app/.local.env`
|
3. `apps/my-app/.env.[target-name]`
|
||||||
4. `apps/my-app/.env.local`
|
4. `apps/my-app/.[target-name].env`
|
||||||
5. `apps/my-app/.env`
|
5. `apps/my-app/.env.local`
|
||||||
6. `.[target-name].env`
|
6. `apps/my-app/.local.env`
|
||||||
7. `.env.[target-name]`
|
7. `apps/my-app/.env`
|
||||||
8. `.local.env`
|
8. `.env.[target-name].[configuration-name]`
|
||||||
9. `.env.local`
|
9. `.[target-name].[configuration-name].env`
|
||||||
10. `.env`
|
10. `.env.[target-name]`
|
||||||
|
11. `.[target-name].env`
|
||||||
|
12. `.local.env`
|
||||||
|
13. `.env.local`
|
||||||
|
14. `.env`
|
||||||
|
|
||||||
{% callout type="warning" title="Order is important" %}
|
{% callout type="warning" title="Order is important" %}
|
||||||
Nx will move through the above list, ignoring files it can't find, and loading environment variables
|
Nx will move through the above list, ignoring files it can't find, and loading environment variables
|
||||||
|
|||||||
@ -385,11 +385,27 @@ export class ForkedProcessTaskRunner {
|
|||||||
...this.getDotenvVariablesForForkedProcess(),
|
...this.getDotenvVariablesForForkedProcess(),
|
||||||
...parseEnv(`.${task.target.target}.env`),
|
...parseEnv(`.${task.target.target}.env`),
|
||||||
...parseEnv(`.env.${task.target.target}`),
|
...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}/.env`),
|
||||||
...parseEnv(`${task.projectRoot}/.local.env`),
|
...parseEnv(`${task.projectRoot}/.local.env`),
|
||||||
...parseEnv(`${task.projectRoot}/.env.local`),
|
...parseEnv(`${task.projectRoot}/.env.local`),
|
||||||
...parseEnv(`${task.projectRoot}/.${task.target.target}.env`),
|
...parseEnv(`${task.projectRoot}/.${task.target.target}.env`),
|
||||||
...parseEnv(`${task.projectRoot}/.env.${task.target.target}`),
|
...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 {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user