Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

refactor: cache assets similar to how the normal compilation does it #325

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion index.js
Expand Up @@ -4,6 +4,7 @@
*/
var fs = require('fs');
var ConcatSource = require("webpack-sources").ConcatSource;
var CachedSource = require("webpack-sources").CachedSource;
var async = require("async");
var ExtractedModule = require("./ExtractedModule");
var Chunk = require("webpack/lib/Chunk");
Expand Down Expand Up @@ -337,8 +338,22 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
});

var file = (isFunction(filename)) ? filename(getPath) : getPath(filename);


var cacheKey = "extracted " + file;
var chunkHash = loaderUtils.getHashDigest(source.source());
if(compilation.cache && compilation.cache[cacheKey] && compilation.cache[cacheKey].hash === chunkHash) {
source = compilation.cache[cacheKey].source;
} else {
if(compilation.cache) {
compilation.cache[cacheKey] = {
hash: chunkHash,
source: source = (source instanceof CachedSource ? source : new CachedSource(source))
};
}
}

compilation.assets[file] = source;
compilation.modifyHash(chunkHash);
chunk.files.push(file);
}
}, this);
Expand Down