Skip to content

Commit 1b63456

Browse files
committed
Extract recordModule
1 parent daf38ec commit 1b63456

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,31 @@ export default class ReactFlightWebpackPlugin {
172172
const json = {};
173173
compilation.chunkGroups.forEach(chunkGroup => {
174174
const chunkIds = chunkGroup.chunks.map(c => c.id);
175+
176+
function recordModule(id, mod) {
177+
// TODO: Hook into deps instead of the target module.
178+
// That way we know by the type of dep whether to include.
179+
// It also resolves conflicts when the same module is in multiple chunks.
180+
if (!/\.client\.js$/.test(mod.resource)) {
181+
return;
182+
}
183+
const moduleExports = {};
184+
['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
185+
moduleExports[name] = {
186+
id: mod.id,
187+
chunks: chunkIds,
188+
name: name,
189+
};
190+
});
191+
const href = pathToFileURL(mod.resource).href;
192+
if (href !== undefined) {
193+
json[href] = moduleExports;
194+
}
195+
}
196+
175197
chunkGroup.chunks.forEach(chunk => {
176198
chunk.getModules().forEach(mod => {
177-
// TODO: Hook into deps instead of the target module.
178-
// That way we know by the type of dep whether to include.
179-
// It also resolves conflicts when the same module is in multiple chunks.
180-
if (!/\.client\.js$/.test(mod.resource)) {
181-
return;
182-
}
183-
const moduleExports = {};
184-
['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
185-
moduleExports[name] = {
186-
id: mod.id,
187-
chunks: chunkIds,
188-
name: name,
189-
};
190-
});
191-
const href = pathToFileURL(mod.resource).href;
192-
if (href !== undefined) {
193-
json[href] = moduleExports;
194-
}
199+
recordModule(mod.id, mod);
195200
});
196201
});
197202
});

0 commit comments

Comments
 (0)