-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): setup mf env var as input for rspack (#29584)
## Current Behavior The Module Federation `NxRuntimeLibraryControlPlugin` relies on an environment variable that is set during the build/serve process. This could potentially lead to issues with cache restoration. The impact should be minimal as the runtime control plugin should only be added to the module federation config when the env var is set. It should only be set by the `module-federation-dev-server` executor which is invoked during serve - a non-cacheable task already. ## Expected Behavior Ensure the env var is set as an input to ensure maximum accuracy with module federation builds via rspack executor
- Loading branch information
Showing
5 changed files
with
32 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
import { type Tree, readNxJson, updateNxJson } from '@nx/devkit'; | ||
|
||
export function addMfEnvToTargetDefaultInputs(tree: Tree) { | ||
export function addMfEnvToTargetDefaultInputs( | ||
tree: Tree, | ||
bundler: 'rspack' | 'webpack' | ||
) { | ||
const nxJson = readNxJson(tree); | ||
const webpackExecutor = '@nx/webpack:webpack'; | ||
const executor = | ||
bundler === 'rspack' ? '@nx/rspack:rspack' : '@nx/webpack:webpack'; | ||
const mfEnvVar = 'NX_MF_DEV_REMOTES'; | ||
|
||
nxJson.targetDefaults ??= {}; | ||
nxJson.targetDefaults[webpackExecutor] ??= {}; | ||
nxJson.targetDefaults[webpackExecutor].inputs ??= [ | ||
'production', | ||
'^production', | ||
]; | ||
nxJson.targetDefaults[webpackExecutor].dependsOn ??= ['^build']; | ||
nxJson.targetDefaults[executor] ??= {}; | ||
nxJson.targetDefaults[executor].inputs ??= ['production', '^production']; | ||
nxJson.targetDefaults[executor].dependsOn ??= ['^build']; | ||
|
||
let mfEnvVarExists = false; | ||
for (const input of nxJson.targetDefaults[webpackExecutor].inputs) { | ||
for (const input of nxJson.targetDefaults[executor].inputs) { | ||
if (typeof input === 'object' && input['env'] === mfEnvVar) { | ||
mfEnvVarExists = true; | ||
break; | ||
} | ||
} | ||
if (!mfEnvVarExists) { | ||
nxJson.targetDefaults[webpackExecutor].inputs.push({ env: mfEnvVar }); | ||
nxJson.targetDefaults[executor].inputs.push({ env: mfEnvVar }); | ||
} | ||
nxJson.targetDefaults[webpackExecutor].cache = true; | ||
nxJson.targetDefaults[executor].cache = true; | ||
updateNxJson(tree, nxJson); | ||
} |