Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class MiniCssExtractPlugin {
// This loop also gathers dependencies from the ordered lists
// Lists are in reverse order to allow to use Array.pop()
const modulesByChunkGroup = Array.from(chunk.groupsIterable, (cg) => {
const sortedModules = modules
let sortedModules = modules
.map((m) => {
return {
module: m,
Expand All @@ -433,6 +433,18 @@ class MiniCssExtractPlugin {
.sort((a, b) => b.index - a.index)
.map((item) => item.module);

// if no modules were found by getModuleIndex2, dive into each chunk
// in the group
if (!sortedModules || !sortedModules.length) {
sortedModules = cg.chunks
// reduce each chunk's modules into a flat array
.reduce((arr, ch) => [...arr, ...ch.modulesIterable], [])
// filter only the modules that match
.filter((m) => modules.find((mod) => mod === m))
// sort in reverse order
.sort((a, b) => a.index2 - b.index2);
}

for (let i = 0; i < sortedModules.length; i++) {
const set = moduleDependencies.get(sortedModules[i]);

Expand Down