From 312ad6dcfcad6a949d3e2458a273f555f8417078 Mon Sep 17 00:00:00 2001 From: Ryan Sullivan Date: Thu, 17 Oct 2019 03:18:16 -0700 Subject: [PATCH] fix(order): find modules from each chunk in group fixes #257 --- src/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index cec08e21..fdb2b2aa 100644 --- a/src/index.js +++ b/src/index.js @@ -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, @@ -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]);