Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(order): find modules from each chunk in group #455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/index.js
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