55
isServer: boolean,
56
clientReferences?: ClientReferencePath | $ReadOnlyArray<ClientReferencePath>,
57
chunkName?: string,
58
- manifestFilename?: string,
58
+ clientManifestFilename?: string,
59
+ ssrManifestFilename?: string,
60
};
61
62
const PLUGIN_NAME = 'React Server Plugin';
64
export default class ReactFlightWebpackPlugin {
65
clientReferences: $ReadOnlyArray<ClientReferencePath>;
66
chunkName: string;
66
- manifestFilename: string;
67
+ clientManifestFilename: string;
68
+ ssrManifestFilename: string;
69
70
constructor(options: Options) {
71
if (!options || typeof options.isServer !== 'boolean') {
101
} else {
102
this.chunkName = 'client[index]';
103
}
102
- this.manifestFilename =
103
- options.manifestFilename || 'react-client-manifest.json';
104
+ this.clientManifestFilename =
105
+ options.clientManifestFilename || 'react-client-manifest.json';
106
+ this.ssrManifestFilename =
107
+ options.ssrManifestFilename || 'react-ssr-manifest.json';
108
}
109
110
apply(compiler: any) {
213
if (clientFileNameFound === false) {
214
compilation.warnings.push(
215
new WebpackError(
212
- `Client runtime at ${clientImportName} was not found. React Server Components module map file ${_this.manifestFilename} was not created.`,
216
+ `Client runtime at ${clientImportName} was not found. React Server Components module map file ${_this.clientManifestFilename} was not created.`,
217
),
218
);
219
return;
220
}
221
218
- const json: {
222
+ const clientManifest: {
223
[string]: {
220
- [string]: {chunks: $FlowFixMe, id: $FlowFixMe, name: string},
224
+ [string]: {chunks: $FlowFixMe, id: string, name: string},
225
+ },
226
+ } = {};
227
+ const ssrManifest: {
228
+ [string]: {
229
+ [string]: {specifier: string, name: string},
230
},
231
} = {};
232
compilation.chunkGroups.forEach(function (chunkGroup) {
248
.getExportsInfo(module)
249
.getProvidedExports();
250
242
- const moduleExports: {
251
+ const clientExports: {
252
[string]: {chunks: $FlowFixMe, id: $FlowFixMe, name: string},
253
} = {};
254
+
255
+ const ssrExports: {
256
+ [string]: {specifier: string, name: string},
257
+ } = {};
258
+
259
+ ssrManifest[id] = ssrExports;
260
+
261
['', '*']
262
.concat(
263
Array.isArray(moduleProvidedExports)
265
: [],
266
)
267
.forEach(function (name) {
252
- moduleExports[name] = {
268
+ clientExports[name] = {
269
id,
270
chunks: chunkIds,
271
name: name,
272
};
273
+ ssrExports[name] = {
274
+ specifier: module.resource,
275
+ name: name,
276
+ };
277
});
278
const href = pathToFileURL(module.resource).href;
279
280
if (href !== undefined) {
261
- json[href] = moduleExports;
281
+ clientManifest[href] = clientExports;
282
+ ssrManifest[href] = ssrExports;
283
}
284
}
285
301
});
302
});
303
283
- const output = JSON.stringify(json, null, 2);
304
+ const clientOutput = JSON.stringify(clientManifest, null, 2);
305
+ compilation.emitAsset(
306
+ _this.clientManifestFilename,
307
+ new sources.RawSource(clientOutput, false),
308
+ );
309
+ const ssrOutput = JSON.stringify(ssrManifest, null, 2);
310
compilation.emitAsset(
285
- _this.manifestFilename,
286
- new sources.RawSource(output, false),
311
+ _this.ssrManifestFilename,
312
+ new sources.RawSource(ssrOutput, false),
313
);
314
},
315
);