Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cyan-badgers-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/nextjs-mf': minor
'@module-federation/node': minor
---

Add skipFederatedStats extraOption to skip federated-stats.json generation for CSR-only apps.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ new NextFederationPlugin({
enableImageLoaderFix: boolean, // `false` by default
enableUrlLoaderFix: boolean, // `false` by default
skipSharingNextInternals: boolean, // `false` by default
skipFederatedStats: boolean // `false` by default
},
});
```
Expand All @@ -79,6 +80,7 @@ new NextFederationPlugin({
- `enableImageLoaderFix` – adds public hostname to all assets bundled by `nextjs-image-loader`. So if you serve remoteEntry from `http://example.com` then all bundled assets will get this hostname in runtime. It's something like Base URL in HTML but for federated modules.
- `enableUrlLoaderFix` – adds public hostname to all assets bundled by `url-loader`.
- `skipSharingNextInternals` – disables sharing of next internals. You can use it if you want to share next internals yourself or want to use this plugin on non next applications
- `skipFederatedStats` – skips generation of `federated-stats.json`. Only consumed by `flushChunks()` during SSR. CSR-only apps that don't use `flushChunks()` can enable this to reduce build time significantly.

## Demo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ new NextFederationPlugin({
enableImageLoaderFix: boolean, // `false` by default
enableUrlLoaderFix: boolean, // `false` by default
skipSharingNextInternals: boolean, // `false` by default
skipFederatedStats: boolean // `false` by default
},
});
```
Expand All @@ -163,6 +164,7 @@ new NextFederationPlugin({
- `enableImageLoaderFix` – 给所有由 `nextjs-image-loader` 打包的资产添加公共主机名。例如,如果你从 `http://example.com` 提供 remoteEntry,则所有打包资产将在运行时获取此主机名。这类似于 HTML 中的 Base URL,但用于联合模块。
- `enableUrlLoaderFix` – 给所有由 `url-loader` 打包的资产添加公共主机名。
- `skipSharingNextInternals` – 禁用共享 Next 内部。如果你想自己共享 Next 内部或在非 next 应用中使用此插件,则可以使用它。
- `skipFederatedStats` – 跳过 `federated-stats.json` 的生成。仅在 SSR 中被 `flushChunks()` 使用。不使用 `flushChunks()` 的纯 CSR 应用可以启用此选项来显著减少构建时间。

## 演示

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function applyClientPlugins(
'static/chunks/federated-stats.json',
'server/federated-stats.json',
],
skip: extraOptions?.skipFederatedStats,
}).apply(compiler);

// Apply the InvertedContainerPlugin to add custom runtime modules to the container runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface NextFederationPluginExtraOptions {
skipSharingNextInternals?: boolean;
automaticPageStitching?: boolean;
debug?: boolean;
skipFederatedStats?: boolean;
}

export interface NextFederationPluginOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface NextFederationPluginExtraOptions {
skipSharingNextInternals?: boolean;
automaticPageStitching?: boolean;
debug?: boolean;
skipFederatedStats?: boolean;
}

export interface NextFederationPluginOptions
Expand All @@ -30,6 +31,7 @@ export function setOptions(options: NextFederationPluginOptions): {
enableUrlLoaderFix: false,
skipSharingNextInternals: false,
debug: false,
skipFederatedStats: false,
};

return {
Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/plugins/ChunkCorrelationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ class FederationStatsPlugin {
* @param {import("webpack").Compiler} compiler
*/
apply(compiler) {
// skip flag allows CSR-only apps to opt out of expensive stats.toJson()
// federated-stats.json is only used for SSR chunk flushing
if (this._options?.skip) {
return;
}

const federationPlugins = compiler.options.plugins?.filter(
(plugin) =>
[
Expand Down
1 change: 1 addition & 0 deletions packages/utilities/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface NextFederationPluginExtraOptions {
skipSharingNextInternals?: boolean;
automaticPageStitching?: boolean;
debug?: boolean;
skipFederatedStats?: boolean;
}

export interface NextFederationPluginOptions extends ModuleFederationPluginOptions {
Expand Down