Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
Arguments:

* `asset`: The target asset name. `[file]` is replaced with the original asset. `[path]` is replaced with the path of the original asset and `[query]` with the query. Defaults to `"[path].gz[query]"`.
* `filename`: A `function(asset)` which receives the asset name (after processing `asset` option) and returns the new asset name. Defaults to `false`.
* `algorithm`: Can be a `function(buf, callback)` or a string. For a string the algorithm is taken from `zlib` (or zopfli for `zopfli`). Defaults to `"gzip"`.
* `test`: All assets matching this RegExp are processed. Defaults to every asset.
* `threshold`: Only assets bigger than this size are processed. In bytes. Defaults to `0`.
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function CompressionPlugin(options) {
options = options || {};
this.asset = options.asset || "[path].gz[query]";
this.algorithm = options.algorithm || "gzip";
this.filename = options.filename || false;
this.compressionOptions = {};
if(typeof this.algorithm === "string") {
if (this.algorithm === "zopfli") {
Expand Down Expand Up @@ -80,6 +81,9 @@ CompressionPlugin.prototype.apply = function(compiler) {
var newFile = this.asset.replace(/\[(file|path|query)\]/g, function(p0,p1) {
return sub[p1];
});
if (typeof this.filename === 'function') {
newFile = this.filename(newFile);
}
assets[newFile] = new RawSource(result);
if (this.deleteOriginalAssets) {
delete assets[file];
Expand Down