Support configuration references/extends in project.json targets #33761
driessamyn
started this conversation in
Feature Requests
Replies: 1 comment
-
|
I have come here to say that this is a pain point i currently have to work around. Im supporting the proposed solutions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Current Limitation
Currently, when multiple projects share identical target configurations (but not all projects), there's no way to define that configuration once and reference it from multiple project.json files.
targetDefaults in nx.json works for global defaults, but applies to all projects. For shared configurations that only apply to a subset of projects, the only option is duplication.
Use Case
I have multiple Vite applications in a monorepo that share identical build configurations with multiple environments. These are ~50+ lines of configuration that need to be kept in sync across projects.
{ "targets": { "build": { "executor": "@nx/vite:build", "defaultConfiguration": "development", "configurations": { "development": { /* ... */ }, "production": { /* ... */ }, "staging": { /* ... */ }, "staging-beta": { /* ... */ }, "analyze": { /* ... */ } } } } }Not all projects use this configuration, so making it a global targetDefault isn't appropriate.
Proposed Solution
Option 1 - Add extends support:
configs/vite-multi-env.json:
{ "defaultConfiguration": "development", "configurations": { /* ... */ } }project.json:
{ "targets": { "build": { "executor": "@nx/vite:build", "extends": "../../configs/vite-multi-env.json" } } }Option 2 - Named target configurations in nx.json:
nx.json:
{ "namedTargetConfigs": { "vite-multi-env": { "defaultConfiguration": "development", "configurations": { /* ... */ } } } }project.json:
{ "targets": { "build": { "executor": "@nx/vite:build", "extends": "vite-multi-env" } } }Benefits
DRY: Define configuration once
Maintainability: Update shared config in one place
Flexibility: Projects can override specific values
Selective: Only applies to projects that opt-in
Alternatives Considered
Beta Was this translation helpful? Give feedback.
All reactions