[Flight] Support concatenated modules in Webpack plugin (#20449)
* Extract recordModule * Add support for concatenated modules
Dan Abramov committed
Dec 13, 2020 at 17:44 UTC
0f80dd1484ce546076c7936329610e7854ef6dff
1 file changed
+28
-17
packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js
+28
-17
@@ -172,25 +172,36 @@ export default class ReactFlightWebpackPlugin {
172
const json = {};
173
compilation.chunkGroups.forEach(chunkGroup => {
174
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: 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
+
197
chunkGroup.chunks.forEach(chunk => {
198
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;
199
+ recordModule(mod.id, mod);
200
+ // If this is a concatenation, register each child to the parent ID.
201
+ if (mod.modules) {
202
+ mod.modules.forEach(concatenatedMod => {
203
+ recordModule(mod.id, concatenatedMod);
204
+ });
205
}
206
});
207
});