Skip to content

Commit 46b12b2

Browse files
committed
better ProgressPlugin and fixed bug for multi-compilation
1 parent 75abfd1 commit 46b12b2

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

bin/convert-argv.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,6 @@ module.exports = function(optimist, argv, convertOptions) {
379379
}));
380380
});
381381

382-
ifBooleanArg("progress", function() {
383-
var ProgressPlugin = require("../lib/ProgressPlugin");
384-
ensureArray(options, "plugins");
385-
options.plugins.push(new ProgressPlugin());
386-
});
387-
388382
ifArg("devtool", function(value) {
389383
options.devtool = value;
390384
});

bin/webpack.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ function processOptions(options) {
151151
var lastHash = null;
152152
var compiler = webpack(options);
153153

154+
if(argv.progress) {
155+
var ProgressPlugin = require("../lib/ProgressPlugin");
156+
compiler.apply(new ProgressPlugin({
157+
profile: argv.profile
158+
}));
159+
}
160+
154161
function compilerCallback(err, stats) {
155162
if(!options.watch) {
156163
// Do not keep cache anymore

lib/ProgressPlugin.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
function ProgressPlugin(handler) {
6-
this.handler = handler;
5+
function ProgressPlugin(options) {
6+
if(typeof options === "function") {
7+
options = {
8+
handler: options
9+
};
10+
}
11+
options = options || {};
12+
this.profile = options.profile;
13+
this.handler = options.handler;
714
}
815
module.exports = ProgressPlugin;
916

1017
ProgressPlugin.prototype.apply = function(compiler) {
1118
var handler = this.handler || defaultHandler;
19+
var profile = this.profile;
1220
if(compiler.compilers) {
1321
var states = new Array(compiler.compilers.length);
1422
compiler.compilers.forEach(function(compiler, idx) {
@@ -18,9 +26,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
1826
return state && state[0] || 0;
1927
}).reduce(function(a, b) {
2028
return a + b;
21-
}) / states.length, states.map(function(state) {
22-
return state && state[1];
23-
}).filter(Boolean).join(" | ")]
29+
}) / states.length, "[" + idx + "] " + msg]
2430
.concat(Array.prototype.slice.call(arguments, 2)));
2531
}));
2632
});
@@ -146,7 +152,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
146152
msg += " " + detail
147153
});
148154
}
149-
if(compiler.options.profile) {
155+
if(profile) {
150156
state = state.replace(/^\d+\/\d+\s+/, "");
151157
if(percentage === 0) {
152158
lastState = null;

0 commit comments

Comments
 (0)