Skip to content

Commit 9a8cae6

Browse files
committed
added NoErrorsPlugin, which doesn't emit on error
fixes webpack/webpack-dev-server#42 fixes webpack#449
1 parent e43a76a commit 9a8cae6

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

lib/Compilation.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,23 @@ Compilation.prototype.seal = function seal(callback) {
484484
return callback(err);
485485
}
486486

487+
var shouldRecord = this.applyPluginsBailResult("should-record") !== false;
488+
487489
this.applyPlugins("revive-modules", this.modules, this.records);
488490
this.applyPlugins("optimize-module-order", this.modules);
489491
this.applyModuleIds();
490492
this.applyPlugins("optimize-module-ids", this.modules);
491493
this.applyPlugins("after-optimize-module-ids", this.modules);
492-
this.applyPlugins("record-modules", this.modules, this.records);
494+
if(shouldRecord)
495+
this.applyPlugins("record-modules", this.modules, this.records);
493496

494497
this.applyPlugins("revive-chunks", this.chunks, this.records);
495498
this.applyPlugins("optimize-chunk-order", this.chunks);
496499
this.applyChunkIds();
497500
this.applyPlugins("optimize-chunk-ids", this.chunks);
498501
this.applyPlugins("after-optimize-chunk-ids", this.chunks);
499-
this.applyPlugins("record-chunks", this.chunks, this.records);
502+
if(shouldRecord)
503+
this.applyPlugins("record-chunks", this.chunks, this.records);
500504

501505
this.sortItems();
502506
this.applyPlugins("before-hash");
@@ -506,7 +510,8 @@ Compilation.prototype.seal = function seal(callback) {
506510
this.createChunkAssets();
507511
this.applyPlugins("additional-chunk-assets", this.chunks);
508512
this.summarizeDependencies();
509-
this.applyPlugins("record", this, this.records);
513+
if(shouldRecord)
514+
this.applyPlugins("record", this, this.records);
510515

511516
this.applyPluginsAsync("additional-assets", function(err) {
512517
if(err) {

lib/Compiler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Watching.prototype._go = function() {
4747
if(err) return this._done(err);
4848
if(this.invalid) return this._done();
4949

50+
if(this.compiler.applyPluginsBailResult("should-emit", compilation) === false) {
51+
return this._done(null, compilation);
52+
}
53+
5054
this.compiler.emitAssets(compilation, function(err) {
5155
if(err) return this._done(err);
5256
if(this.invalid) return this._done();
@@ -166,6 +170,11 @@ Compiler.prototype.run = function(callback) {
166170
this.compile(function(err, compilation) {
167171
if(err) return callback(err);
168172

173+
if(this.applyPluginsBailResult("should-emit", compilation) === false) {
174+
callbackStats.call(this);
175+
return;
176+
}
177+
169178
this.emitAssets(compilation, function(err) {
170179
if(err) return callback(err);
171180

lib/NoErrorsPlugin.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
function NoErrorsPlugin() {
6+
}
7+
module.exports = NoErrorsPlugin;
8+
NoErrorsPlugin.prototype.apply = function(compiler) {
9+
compiler.plugin("should-emit", function(compilation) {
10+
if(compilation.errors.length > 0)
11+
return false;
12+
});
13+
compiler.plugin("compilation", function(compilation) {
14+
compilation.plugin("should-record", function() {
15+
if(compilation.errors.length > 0)
16+
return false;
17+
});
18+
});
19+
};

lib/webpack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ exportPlugins(exports, ".", [
7373
"ProgressPlugin",
7474
"SetVarMainTemplatePlugin",
7575
"UmdMainTemplatePlugin",
76+
"NoErrorsPlugin",
7677
]);
7778
exportPlugins(exports.optimize = {}, "./optimize", [
7879
"AggressiveMergingPlugin",

0 commit comments

Comments
 (0)