Skip to content

Commit 312ad6d

Browse files
committed
fix(order): find modules from each chunk in group
fixes #257
1 parent 50434b5 commit 312ad6d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class MiniCssExtractPlugin {
421421
// This loop also gathers dependencies from the ordered lists
422422
// Lists are in reverse order to allow to use Array.pop()
423423
const modulesByChunkGroup = Array.from(chunk.groupsIterable, (cg) => {
424-
const sortedModules = modules
424+
let sortedModules = modules
425425
.map((m) => {
426426
return {
427427
module: m,
@@ -433,6 +433,18 @@ class MiniCssExtractPlugin {
433433
.sort((a, b) => b.index - a.index)
434434
.map((item) => item.module);
435435

436+
// if no modules were found by getModuleIndex2, dive into each chunk
437+
// in the group
438+
if (!sortedModules || !sortedModules.length) {
439+
sortedModules = cg.chunks
440+
// reduce each chunk's modules into a flat array
441+
.reduce((arr, ch) => [...arr, ...ch.modulesIterable], [])
442+
// filter only the modules that match
443+
.filter((m) => modules.find((mod) => mod === m))
444+
// sort in reverse order
445+
.sort((a, b) => a.index2 - b.index2);
446+
}
447+
436448
for (let i = 0; i < sortedModules.length; i++) {
437449
const set = moduleDependencies.get(sortedModules[i]);
438450

0 commit comments

Comments
 (0)