Skip to content

Commit 8a7b508

Browse files
committed
cache the replaced source for performance
1 parent d69a884 commit 8a7b508

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/NormalModule.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ NormalModule.prototype.build = function build(options, compilation, resolver, fs
6666
this.dependencies.length = 0;
6767
this.variables.length = 0;
6868
this.blocks.length = 0;
69+
this._cachedSource = null;
6970
if(options.module && options.module.noParse) {
7071
if(Array.isArray(options.module.noParse)) {
7172
if(options.module.noParse.some(function(regExp) {
@@ -96,9 +97,10 @@ NormalModule.prototype.build = function build(options, compilation, resolver, fs
9697
};
9798

9899
NormalModule.prototype.source = function(dependencyTemplates, outputOptions, requestShortener) {
100+
if(this._cachedSource) return this._cachedSource;
99101
var _source = this._source;
100102
if(!_source) return new RawSource("throw new Error('No source availible');");
101-
var source = new ReplaceSource(_source);
103+
var source = this._cachedSource = new ReplaceSource(_source);
102104
var topLevelBlock = this;
103105
function doDep(dep) {
104106
var template = dependencyTemplates.get(dep.Class);

0 commit comments

Comments
 (0)