Skip to content

Commit

Permalink
feat: add option to delete original assets (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvn authored and joshwiens committed Apr 8, 2017
1 parent 31e9304 commit 24f15f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Arguments:
* `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`.
* `minRatio`: Only assets that compress better that this ratio are processed. Defaults to `0.8`.
* `deleteOriginalAssets`: Whether to delete the original assets or not. Defaults to `false`.

Option Arguments for Zopfli (see [node-zopfli](https://github.com/pierreinglebert/node-zopfli#options) doc for details):
* verbose: Default: false,
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function CompressionPlugin(options) {
this.test = options.test || options.regExp;
this.threshold = options.threshold || 0;
this.minRatio = options.minRatio || 0.8;
this.deleteOriginalAssets = options.deleteOriginalAssets || false;
}
module.exports = CompressionPlugin;

Expand Down Expand Up @@ -80,6 +81,9 @@ CompressionPlugin.prototype.apply = function(compiler) {
return sub[p1];
});
assets[newFile] = new RawSource(result);
if (this.deleteOriginalAssets) {
delete assets[file];
}
callback();
}.bind(this));
}.bind(this), callback);
Expand Down

0 comments on commit 24f15f2

Please sign in to comment.