Skip to content

Commit ca271ab

Browse files
authored
feat: support config manifest (#2319)
1 parent 71559fb commit ca271ab

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

.changeset/twelve-peas-melt.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/manifest': patch
3+
'@module-federation/sdk': patch
4+
---
5+
6+
feat: support config manifest

packages/manifest/src/ManifestManager.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface GenerateManifestOptions {
2121
stats: Stats;
2222
publicPath: string;
2323
compiler: Compiler;
24+
bundler: 'webpack' | 'rspack';
25+
additionalData?: moduleFederationPlugin.PluginManifestOptions['additionalData'];
2426
}
2527

2628
class ManifestManager {
@@ -39,8 +41,15 @@ class ManifestManager {
3941
return getFileName(this._options.manifest).manifestFileName;
4042
}
4143

42-
generateManifest(options: GenerateManifestOptions): void {
43-
const { compilation, publicPath, stats, compiler } = options;
44+
async generateManifest(options: GenerateManifestOptions): Promise<void> {
45+
const {
46+
compilation,
47+
publicPath,
48+
stats,
49+
compiler,
50+
bundler,
51+
additionalData,
52+
} = options;
4453
const manifest: Manifest = {
4554
...stats,
4655
};
@@ -96,9 +105,23 @@ class ManifestManager {
96105

97106
const manifestFileName = this.fileName;
98107

108+
if (additionalData) {
109+
const ret = await additionalData({
110+
manifest: this._manifest,
111+
stats,
112+
pluginOptions: this._options,
113+
compiler,
114+
compilation,
115+
bundler,
116+
});
117+
this._manifest = ret || this._manifest;
118+
}
119+
99120
compilation.emitAsset(
100121
manifestFileName,
101-
new compiler.webpack.sources.RawSource(JSON.stringify(manifest, null, 2)),
122+
new compiler.webpack.sources.RawSource(
123+
JSON.stringify(this._manifest, null, 2),
124+
),
102125
);
103126

104127
if (isDev()) {

packages/manifest/src/StatsPlugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class StatsPlugin implements WebpackPluginInstance {
1010
private _statsManager: StatsManager = new StatsManager();
1111
private _manifestManager: ManifestManager = new ManifestManager();
1212
private _enable: boolean = true;
13+
private _bundler: 'webpack' | 'rspack' = 'webpack';
1314

1415
constructor(
1516
options: moduleFederationPlugin.ModuleFederationPluginOptions,
@@ -20,6 +21,7 @@ export class StatsPlugin implements WebpackPluginInstance {
2021
) {
2122
try {
2223
this._options = options;
24+
this._bundler = bundler;
2325
this._statsManager.init(this._options, { pluginVersion, bundler });
2426
this._manifestManager.init(this._options);
2527
} catch (err) {
@@ -57,6 +59,11 @@ export class StatsPlugin implements WebpackPluginInstance {
5759
stats,
5860
publicPath: this._statsManager.getPublicPath(compiler),
5961
compiler,
62+
bundler: this._bundler,
63+
additionalData:
64+
typeof this._options.manifest === 'object'
65+
? this._options.manifest.additionalData
66+
: undefined,
6067
});
6168
}
6269
},

packages/sdk/src/types/plugins/ModuleFederationPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type webpack from 'webpack';
22
import { Stats } from '../stats';
3+
import { Manifest } from '../manifest';
34
/**
45
* Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.
56
*/
@@ -109,6 +110,7 @@ export type SharedItem = string;
109110

110111
export interface AdditionalDataOptions {
111112
stats: Stats;
113+
manifest?: Manifest;
112114
pluginOptions: ModuleFederationPluginOptions;
113115
compiler: webpack.Compiler;
114116
compilation: webpack.Compilation;

0 commit comments

Comments
 (0)