19 Commits

Author SHA1 Message Date
Nicholas Cunningham
939cc732de
fix(module-federation): remove disabling runtimeChunk (#30637)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
When using Module Federation with an app that defines styles as a
separate entry point, HMR fails to update in the browser. Instead of
updating automatically, a warning is shown in the console related to a
missing chunk. A full-page reload is typically required, which is not
the intended behaviour.


## Expected Behavior
<!-- This is the behaviour we should expect with the changes in this PR
-->
HMR should work with styles as an entrypoint.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
The default is for `runtimeChunk` is `config.optimization.runtimeChunk =
{name: 'runtime'}` it is _not_ the same as `single` but the naming will
be the same.

Fixes #9582
2025-04-24 12:08:35 -06:00
Colum Ferry
745abdaecf
fix(angular): convert-to-rspack correctly migrating existing custom webpack configs (#30778)
## Current Behavior
The `createConfig` helper from `@nx/angular-rspack` became an async
function.
This meant that the handling of custom webpack configs in the migration
done by `convert-to-rspack` was incorrect.

## Expected Behavior
Ensure the migration is handled correctly.
Ensure that Module Federation migrations work correctly.

## Related Issues
Fixes https://github.com/nrwl/angular-rspack/issues/53
2025-04-22 15:54:51 +01:00
Colum Ferry
9669dfdb62
feat(react): add crystal mf support to host and remote (#30424)
## Current Behavior
The `@nx/react` `host` and `remote` generators currently use executors
to support Module Federation


## Expected Behavior
When `bundler=rspack` use Crystal Module Federation with no executors
for Module Federation

## Related Issues
#30391
2025-04-02 16:58:45 +01:00
Colum Ferry
487aa6fa78
feat(module-federation): add ssr support to rspack crystal plugin (#30437)
## Current Behavior
The current `NxModuleFederationPlugin` does not support SSR


## Expected Behavior
The current `NxModuleFederationPlugin` supports SSR
2025-03-21 15:17:45 +00:00
Colum Ferry
32341d5efc
fix(module-federation): handle parsing static remote config correctly (#30168)
## Current Behavior
When the dist for a project lives in the projectRoot, the
`parseStaticRemotesConfig` util function for executors is not correctly
handling the outputPath and urlSegment

## Expected Behavior
Ensure that the parsed config is correct regardless of whether the dist
is in the projectRoot or not

## Related Issue(s)

Fixes #30138
2025-02-25 15:18:58 +00:00
Colum Ferry
e643899a57
fix(module-federation): handle remote output paths (#30119)
## Current Behavior
`parseRemotesConfig` is naively handling detection of remote output
paths needed for standing up the single file server.


## Expected Behavior
Provide better detection of remote output paths that covers inference
and executor usage with fallback behaviour
2025-02-20 15:54:01 -05:00
Colum Ferry
090364ad39
feat(module-federation): add NxModuleFederationPlugin for inferred usage (#30003)
## Current Behaviour
Currently, Module Federation with Nx is forced to use executors to
provide the best DX.

## Expected Behaviour
As part of the transition to inferred targets, we will need Rspack
plugins that replicates the DX provided by our executors.
Add `NxModuleFederationPlugin` and `NxModuleFederationDevServerPlugin`
to handle this.
2025-02-17 15:21:36 +00:00
Colum Ferry
07f1215411
fix(module-federation): tuple remotes should have global identifier added if missing (#29811)
## Current Behavior
Our Module Federation Config allows passing tuple remotes:

```js
remotes: [
  ["remote1", "http://localhost:4201/remoteEntry.js"]
]
```

However, if the Module Federation system is expecting the remotes to be
loaded as Global variables in the browser, then we erroneously pass just
the url to webpack/rspack's `extractUrlAndGlobal` method.

This expects a string of format `name@url`. For non-tuple remote
configurations, we create this correctly.
However, when a tuple is passed, we simply return the url.


## Expected Behavior
We should ensure that the string is massaged to `name@url` even when a
tuple is provided.
2025-01-30 12:52:46 +00:00
Colum Ferry
16c8ba164c
fix(module-federation): dynamic federation helpers should normalize remote names (#29427)
## Current Behavior
After migration of existing remotes beyond Nx 19.8, dynamic manifest
federation files may be updated to match the normalized names of JS
variables (`_` instead of `-`).
Project names will not have been migrated, and therefore the logic to
find the projects based on the remote names is broken.

## Expected Behavior
Check the project graph for remote names as-is and by transforming `_`
to `-` to see if the project exists
2024-12-19 17:17:27 +00:00
Colum Ferry
5448046f06
feat(module-federation): move common executor logic to module-federation package (#29151)
## Current Behavior
The logic for the `module-federation-dev-server` and
`module-federation-ssr-dev-server` is duplicated across Angular, React
and Rspack.

The majority of this logic is the same, and the duplication causes an
increased maintenance tax.

## Expected Behavior
Move the logic into a utility that is exposed from
`@nx/module-federation`.
2024-12-03 08:15:20 -05:00
Colum Ferry
182b46ca66
fix(module-federation): use 'hoisted' runtime for node to prevent issues with eager sharing (#29104)
## Current Behavior
SSR with Module Federation frequently encounters issues related to the
eager resolution of shared packages.
This has resulted in numerous erroneous behaviours including but not
limited to:
- Failure to start server
- Failure to resolve remotes
- Failure to server render remotes

## Expected Behavior
Using the `'hoisted'` runtime provided by MF 2.0, we can ensure that SSR
for Module Federation runs in an async environment, removing the issues
surrounding eager consumption and resolution of shared modules.
In testing, this has fixed the issues outlined above

## Related Issue(s)

Fixes #27000
Fixes #27964
2024-11-28 11:38:17 +00:00
Colum Ferry
840d935d2e
feat(module-federation): move withModuleFederation for rspack to new package (#29045)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The `withModuleFederation` helper currently lives in the `@nx/rspack`
package.
With the goal of consolidating the module federation support into a
single package, this introduces a divergence in where module-federation
support lies


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Move `withModuleFederation` helper for angular into the
`@nx/module-federation` package, exposed via
`@nx/module-federation/rspack`.
Adds a migration to migrate existing projects to use the new package

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-11-22 13:26:00 -05:00
Colum Ferry
432d9d3b17
feat(module-federation): move withModuleFederation for webpack to new package (#29031)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The `withModuleFederation` helper currently lives in the `@nx/react`
package.
With the goal of consolidating the module federation support into a
single package, this introduces a divergence in where module-federation
support lies


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Move `withModuleFederation` helper for angular into the
`@nx/module-federation` package, exposed via
`@nx/module-federation/webpack`.
Adds a migration to migrate existing projects to use the new package

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-11-22 08:28:13 -05:00
Colum Ferry
9ca15f75b0
feat(module-federation): move withModuleFederation for angular to new package (#29021)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The `withModuleFederation` helper currently lives in the `@nx/angular`
package.
With the goal of consolidating the module federation support into a
single package, this introduces a divergence in where module-federation
support lies


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Move `withModuleFederation` helper for angular into the
`@nx/module-federation` package, exposed via
`@nx/module-federation/angular`.
Adds a migration to migrate existing projects to use the new package

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-11-21 11:07:51 -05:00
Colum Ferry
76d61ea5e6
feat(module-federation): consolidate module federation utils into module-federation package (#28919)
- feat(module-federation): consolidate module federation utils into
module-federation package
- chore(module-federation): fix tests and linting

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Our current support for Module Federation relies on utilities that are
spread and duplicated across the `@nx/webpack` package and the
`@nx/rspack` package.



## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Now that we have a `@nx/module-federation` package, dedupe the utils and
consolidate them into a single package

## Todo
- [x] Migrations for React + Angular to install `@nx/module-federation`
and point `ModuleFederationConfig` export to that package from
webpack.config and rspack.config files
2024-11-18 14:15:10 -05:00
Colum Ferry
cfd87f0643 Revert "feat(module-federation): add and expose share helpers and types (#12989)"
This reverts commit e08d7848b33c7fc271b470a1251747efd59d33a0.
2022-11-08 12:43:34 +00:00
Colum Ferry
7783fe0c4d Revert "feat(module-federation): expose additional helpers (#12990)"
This reverts commit 080543e76dcd980067e6aa55ae71bc4da905cafc.
2022-11-08 12:43:34 +00:00
Colum Ferry
080543e76d
feat(module-federation): expose additional helpers (#12990) 2022-11-04 12:58:10 +00:00
Colum Ferry
e08d7848b3
feat(module-federation): add and expose share helpers and types (#12989) 2022-11-04 12:01:22 +00:00