mirror of https://github.com/webpack/webpack.git
Merge pull request #4483 from timse/improve-performance-FlagDependencyExportsPlugin
Improve performance flag dependency exports plugin
This commit is contained in:
commit
416e5beeb4
|
|
@ -9,21 +9,24 @@ class FlagDependencyExportsPlugin {
|
|||
apply(compiler) {
|
||||
compiler.plugin("compilation", (compilation) => {
|
||||
compilation.plugin("finish-modules", (modules) => {
|
||||
|
||||
const dependencies = Object.create(null);
|
||||
|
||||
let module;
|
||||
let moduleWithExports;
|
||||
let moduleProvidedExports;
|
||||
const queue = modules.filter((m) => !m.providedExports);
|
||||
for(let i = 0; i < queue.length; i++) {
|
||||
module = queue[i];
|
||||
|
||||
if(module.providedExports !== true) {
|
||||
moduleWithExports = false;
|
||||
moduleProvidedExports = Array.isArray(module.providedExports) ? new Set(module.providedExports) : new Set();
|
||||
processDependenciesBlock(module);
|
||||
if(!moduleWithExports) {
|
||||
module.providedExports = true;
|
||||
notifyDependencies();
|
||||
} else if(module.providedExports !== true) {
|
||||
module.providedExports = Array.from(moduleProvidedExports);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +39,7 @@ class FlagDependencyExportsPlugin {
|
|||
depBlock.blocks.forEach(processDependenciesBlock);
|
||||
}
|
||||
|
||||
function processDependency(dep, usedExports) {
|
||||
function processDependency(dep) {
|
||||
const exportDesc = dep.getExports && dep.getExports();
|
||||
if(!exportDesc) return;
|
||||
moduleWithExports = true;
|
||||
|
|
@ -65,12 +68,7 @@ class FlagDependencyExportsPlugin {
|
|||
module.providedExports = true;
|
||||
changed = true;
|
||||
} else if(Array.isArray(exports)) {
|
||||
if(Array.isArray(module.providedExports)) {
|
||||
changed = addToSet(module.providedExports, exports);
|
||||
} else {
|
||||
module.providedExports = exports.slice();
|
||||
changed = true;
|
||||
}
|
||||
changed = addToSet(moduleProvidedExports, exports);
|
||||
}
|
||||
}
|
||||
if(changed) {
|
||||
|
|
@ -89,8 +87,8 @@ class FlagDependencyExportsPlugin {
|
|||
function addToSet(a, b) {
|
||||
let changed = false;
|
||||
b.forEach((item) => {
|
||||
if(a.indexOf(item) < 0) {
|
||||
a.push(item);
|
||||
if(!a.has(item)) {
|
||||
a.add(item);
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue