mirror of https://github.com/webpack/webpack.git
improvements from review
This commit is contained in:
parent
4a25a17bb6
commit
5d9eef85c7
|
|
@ -52,19 +52,10 @@ class ModuleConcatenationPlugin {
|
|||
if(!module.reasons.every(reason => reason.dependency instanceof HarmonyImportDependency))
|
||||
return false;
|
||||
|
||||
// It must be statically known which exports are provided or used
|
||||
if(!Array.isArray(module.providedExports))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}));
|
||||
const possibleRoots = relevantModules.filter(module => {
|
||||
return true;
|
||||
});
|
||||
const concatConfigurations = [];
|
||||
while(possibleRoots.length) {
|
||||
const currentRoot = possibleRoots.pop();
|
||||
// console.log("#process", currentRoot.debugId, currentRoot.resource);
|
||||
for(const currentRoot of relevantModules) {
|
||||
const currentConfiguration = new ConcatConfiguration(currentRoot);
|
||||
for(const imp of this.getImports(currentRoot)) {
|
||||
this.tryToAdd(currentConfiguration, imp, possibleInners);
|
||||
|
|
@ -72,26 +63,30 @@ class ModuleConcatenationPlugin {
|
|||
if(!currentConfiguration.isEmpty())
|
||||
concatConfigurations.push(currentConfiguration);
|
||||
}
|
||||
// HACK: Sort configurations by length and start with the longest one
|
||||
// to get the biggers groups possible. Used modules are marked with usedModules
|
||||
// TODO: Allow to reuse existing configuration while trying to add dependencies.
|
||||
// This would improve performance. O(n^2) -> O(n)
|
||||
concatConfigurations.sort((a, b) => {
|
||||
return b.modules.size - a.modules.size;
|
||||
});
|
||||
const usedModules = new Set();
|
||||
for(const config of concatConfigurations) {
|
||||
if(usedModules.has(config.rootModule))
|
||||
for(const concatConfiguration of concatConfigurations) {
|
||||
if(usedModules.has(concatConfiguration.rootModule))
|
||||
continue;
|
||||
const orderedModules = new Set();
|
||||
this.addInOrder(config.rootModule, config.modules, orderedModules);
|
||||
const newModule = new ConcatenatedModule(config.rootModule, Array.from(orderedModules));
|
||||
this.addInOrder(concatConfiguration.rootModule, concatConfiguration.modules, orderedModules);
|
||||
const newModule = new ConcatenatedModule(concatConfiguration.rootModule, Array.from(orderedModules));
|
||||
for(const m of orderedModules) {
|
||||
usedModules.add(m);
|
||||
chunk.removeModule(m);
|
||||
}
|
||||
chunk.addModule(newModule);
|
||||
compilation.modules.push(newModule);
|
||||
if(chunk.entryModule === config.rootModule)
|
||||
if(chunk.entryModule === concatConfiguration.rootModule)
|
||||
chunk.entryModule = newModule;
|
||||
config.rootModule.reasons.forEach(reason => {
|
||||
if(!config.modules.has(reason.module))
|
||||
concatConfiguration.rootModule.reasons.forEach(reason => {
|
||||
if(!concatConfiguration.modules.has(reason.module))
|
||||
reason.dependency.module = newModule;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue