mirror of https://github.com/webpack/webpack.git
Store `recordsPath` paths relative to `options.context`
deduplicated modules can be stored in records fixes #295
This commit is contained in:
parent
c4db71c9d6
commit
44cfedd24e
|
@ -213,7 +213,14 @@ NormalModule.prototype.getAllModuleDependencies = function() {
|
|||
return list;
|
||||
};
|
||||
|
||||
NormalModule.prototype.createTemplate = function(keepModules) {
|
||||
NormalModule.prototype.createTemplate = function(keepModules, roots) {
|
||||
roots.sort(function(a, b) {
|
||||
var ia = a.identifier();
|
||||
var ib = b.identifier();
|
||||
if(ia < ib) return -1;
|
||||
if(ib < ia) return 1;
|
||||
return 0;
|
||||
});
|
||||
var template = new NormalModule("", "", "", [], "", null);
|
||||
template._source = this._source;
|
||||
template.built = this.built;
|
||||
|
@ -224,6 +231,13 @@ NormalModule.prototype.createTemplate = function(keepModules) {
|
|||
return m.id;
|
||||
}).join(", ");
|
||||
};
|
||||
template.identifier = function() {
|
||||
var array = roots.map(function(m) {
|
||||
return m.identifier();
|
||||
});
|
||||
array.sort();
|
||||
return array.join("|");
|
||||
};
|
||||
var args = template.arguments = [];
|
||||
function doDeps(deps) {
|
||||
return deps.map(function(dep) {
|
||||
|
|
|
@ -2,9 +2,19 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var path = require("path");
|
||||
|
||||
function RecordIdsPlugin() {
|
||||
}
|
||||
module.exports = RecordIdsPlugin;
|
||||
|
||||
function makeRelative(compiler, identifier) {
|
||||
var context = compiler.context;
|
||||
return identifier.split("|").map(function(str) {
|
||||
return path.relative(context, str);
|
||||
}).join("|");
|
||||
}
|
||||
|
||||
RecordIdsPlugin.prototype.apply = function(compiler) {
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.plugin("record-modules", function(modules, records) {
|
||||
|
@ -12,7 +22,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
if(!records.modules) records.modules = {};
|
||||
if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
|
||||
modules.forEach(function(module) {
|
||||
var identifier = module.identifier();
|
||||
var identifier = makeRelative(compiler, module.identifier());
|
||||
records.modules.byIdentifier[identifier] = module.id;
|
||||
});
|
||||
});
|
||||
|
@ -23,7 +33,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
var usedIds = {0: true};
|
||||
modules.forEach(function(module) {
|
||||
if(module.id !== null) return;
|
||||
var identifier = module.identifier();
|
||||
var identifier = makeRelative(compiler, module.identifier());
|
||||
var id = records.modules.byIdentifier[identifier];
|
||||
if(id === undefined) return;
|
||||
if(usedIds[id]) return;
|
||||
|
@ -42,7 +52,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
block = block.parent;
|
||||
}
|
||||
if(!block.identifier) return null;
|
||||
ident.unshift(block.identifier());
|
||||
ident.unshift(makeRelative(compiler, block.identifier()));
|
||||
return ident.join(":");
|
||||
}
|
||||
compilation.plugin("record-chunks", function(chunks, records) {
|
||||
|
@ -112,4 +122,4 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -81,7 +81,7 @@ DedupePlugin.prototype.apply = function(compiler) {
|
|||
var commonModules = roots.commonModules;
|
||||
var initialLength = roots.initialCommonModulesLength;
|
||||
if(initialLength !== commonModules.length) {
|
||||
var template = roots[0].createTemplate(commonModules);
|
||||
var template = roots[0].createTemplate(commonModules, roots.slice());
|
||||
roots.template = template;
|
||||
chunk.addModule(template);
|
||||
template.addChunk(chunk);
|
||||
|
|
Loading…
Reference in New Issue