Skip to content

Commit

Permalink
fix(order): find modules from each chunk in group
Browse files Browse the repository at this point in the history
fixes #257
  • Loading branch information
ryansully committed Oct 17, 2019
1 parent 50434b5 commit 312ad6d
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 312ad6d

Please sign in to comment.