Skip to content

Commit

Permalink
[Flight] Fix webpack plugin to use chunk groups
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Dec 10, 2020
1 parent 842ee36 commit 36456d7
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,29 @@ export default class ReactFlightWebpackPlugin {

compiler.hooks.emit.tap(PLUGIN_NAME, compilation => {
const json = {};
compilation.chunks.forEach(chunk => {
chunk.getModules().forEach(mod => {
// TOOD: Hook into deps instead of the target module.
// That way we know by the type of dep whether to include.
// It also resolves conflicts when the same module is in multiple chunks.
if (!/\.client\.js$/.test(mod.resource)) {
return;
}
const moduleExports = {};
['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
moduleExports[name] = {
id: mod.id,
chunks: chunk.ids,
name: name,
};
compilation.chunkGroups.forEach(chunkGroup => {
const chunkIds = chunkGroup.chunks.map(c => c.id);
chunkGroup.chunks.forEach(chunk => {
chunk.getModules().forEach(mod => {
// TODO: Hook into deps instead of the target module.
// That way we know by the type of dep whether to include.
// It also resolves conflicts when the same module is in multiple chunks.
if (!/\.client\.js$/.test(mod.resource)) {
return;
}
const moduleExports = {};
['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
moduleExports[name] = {
id: mod.id,
chunks: chunkIds,
name: name,
};
});
const href = pathToFileURL(mod.resource).href;
if (href !== undefined) {
json[href] = moduleExports;
}
});
const href = pathToFileURL(mod.resource).href;
if (href !== undefined) {
json[href] = moduleExports;
}
});
});
const output = JSON.stringify(json, null, 2);
Expand Down

0 comments on commit 36456d7

Please sign in to comment.