Skip to content

Commit

Permalink
feat(options): add failOnUnused to enable generating error
Browse files Browse the repository at this point in the history
* Original commit: 33d7a62
* Original author: @oliviertassinari
* Closes #3
  • Loading branch information
tomchentw committed Sep 7, 2015
1 parent 787d10a commit 7b7620d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var glob = require("glob");
function UnusedFilesWebpackPlugin (_options_) {
var options = this.options = _options_ || {};
options.pattern = options.pattern || "**/*.*";
options.failOnUnused = options.failOnUnused === true;

var globOptions = this.globOptions = objectAssign({
ignore: "node_modules/**/*"
Expand All @@ -22,7 +23,7 @@ UnusedFilesWebpackPlugin.prototype.apply = function(compiler) {
UnusedFilesWebpackPlugin.prototype._applyAfterEmit = function(compiler, compilation, done) {
var globOptions = this._getGlobOptions(compiler);

glob(this.options.pattern, globOptions, onGlobResult);
glob(this.options.pattern, globOptions, onGlobResult.bind(this));

var fileDepsMap = this._getFileDepsMap(compilation);

Expand All @@ -37,8 +38,13 @@ UnusedFilesWebpackPlugin.prototype._applyAfterEmit = function(compiler, compilat
});
if (unused.length) {
var errmsg = "UnusedFilesWebpackPlugin found some unused files:\n" + unused.join("\n");
var error = new Error(errmsg);

compilation.warnings.push(new Error(errmsg));
if (this.options.failOnUnused) {
compilation.errors.push(error);
} else {
compilation.warnings.push(error);
}
}
}
done();
Expand Down

0 comments on commit 7b7620d

Please sign in to comment.