Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to delete the original assets #44

Merged
merged 1 commit into from Mar 12, 2017
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 @@ -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