Skip to content

Commit

Permalink
make CommonJsRequireContextDependency dedupable
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 26, 2014
1 parent 61e0212 commit 7b97101
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/dependencies/ContextDependencyTemplateAsRequireCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ ContextDependencyTemplateAsRequireCall.prototype.apply = function(dep, source, o
source.replace(dep.range[0], dep.range[1]-1, content);
}
};

ContextDependencyTemplateAsRequireCall.prototype.applyAsTemplateArgument = function(name, dep, source, outputOptions, requestShortener) {
if(dep.valueRange) {
source.replace(dep.valueRange[1], dep.range[1]-1, ")");
source.replace(dep.range[0], dep.valueRange[0]-1, "__webpack_require__(" + name + ")(" + (typeof dep.prepend === "string" ? JSON.stringify(dep.prepend) : "") + "");
} else {
source.replace(dep.range[0], dep.range[1]-1, "__webpack_require__(" + name + ")");
}
};
4 changes: 3 additions & 1 deletion test/cases/compile/deduplication/dedupe1/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = require("../d") + require("./dupdep");
module.exports = require("../d") + require("./dupdep");
var ep = "ep";
require("./dupd" + ep);
4 changes: 3 additions & 1 deletion test/cases/compile/deduplication/dedupe2/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = require("../d") + require("./dupdep");
module.exports = require("../d") + require("./dupdep");
var ep = "ep";
require("./dupd" + ep);

0 comments on commit 7b97101

Please sign in to comment.