Skip to content

Commit

Permalink
fix: improves sorting of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Feb 18, 2021
1 parent c5ba6d7 commit c3eb08b
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,22 +322,6 @@ class MiniCssExtractPlugin {
}
}

sortedModules(compilation, chunk, modules, requestShortener) {
let cache = this._sortedModulesCache.get(chunk);

if (!cache && modules) {
cache = this.sortModules(
compilation,
chunk,
[...modules],
requestShortener
);
this._sortedModulesCache.set(chunk, cache);
}

return cache;
}

/** @param {import("webpack").Compiler} compiler */
apply(compiler) {
const webpack = compiler.webpack
Expand Down Expand Up @@ -553,7 +537,7 @@ class MiniCssExtractPlugin {
? Array.from(this.getChunkModules(chunk, chunkGraph)).filter(
(module) => module.type === MODULE_TYPE
)
: this.sortedModules(
: this.sortModules(
compilation,
chunk,
chunkGraph.getChunkModulesIterableBySourceType(
Expand Down Expand Up @@ -1103,7 +1087,13 @@ class MiniCssExtractPlugin {
}

sortModules(compilation, chunk, modules, requestShortener) {
let usedModules;
let usedModules = this._sortedModulesCache.get(chunk);

if (usedModules || !modules) {
return usedModules;
}

modules = [...modules];

const [chunkGroup] = chunk.groupsIterable;
const moduleIndexFunctionName =
Expand Down Expand Up @@ -1241,11 +1231,13 @@ class MiniCssExtractPlugin {
usedModules = modules;
}

this._sortedModulesCache.set(chunk, usedModules);

return usedModules;
}

renderContentAsset(compiler, compilation, chunk, modules, requestShortener) {
const usedModules = this.sortedModules(
const usedModules = this.sortModules(
compilation,
chunk,
modules,
Expand Down

0 comments on commit c3eb08b

Please sign in to comment.