[Flight] Fix webpack plugin to use chunk groups (#20421)
Dan Abramov committed
Dec 10, 2020 at 03:03 UTC
94aa365e3abfa3ae946875fe2e957ebdcf1d00bc
1 file changed
+22
-19
packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js
+22
-19
@@ -170,26 +170,29 @@ export default class ReactFlightWebpackPlugin {
170
171
compiler.hooks.emit.tap(PLUGIN_NAME, compilation => {
172
const json = {};
173
- compilation.chunks.forEach(chunk => {
174
- chunk.getModules().forEach(mod => {
175
- // TOOD: Hook into deps instead of the target module.
176
- // That way we know by the type of dep whether to include.
177
- // It also resolves conflicts when the same module is in multiple chunks.
178
- if (!/\.client\.js$/.test(mod.resource)) {
179
- return;
180
- }
181
- const moduleExports = {};
182
- ['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
183
- moduleExports[name] = {
184
- id: mod.id,
185
- chunks: chunk.ids,
186
- name: name,
187
- };
173
+ compilation.chunkGroups.forEach(chunkGroup => {
174
+ const chunkIds = chunkGroup.chunks.map(c => c.id);
175
+ chunkGroup.chunks.forEach(chunk => {
176
+ 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
+ }
195
});
189
- const href = pathToFileURL(mod.resource).href;
190
- if (href !== undefined) {
191
- json[href] = moduleExports;
192
- }
196
});
197
});
198
const output = JSON.stringify(json, null, 2);