Skip to content

Commit

Permalink
better ProgressPlugin and fixed bug for multi-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 9, 2016
1 parent 75abfd1 commit 46b12b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 0 additions & 6 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,6 @@ module.exports = function(optimist, argv, convertOptions) {
}));
});

ifBooleanArg("progress", function() {
var ProgressPlugin = require("../lib/ProgressPlugin");
ensureArray(options, "plugins");
options.plugins.push(new ProgressPlugin());
});

ifArg("devtool", function(value) {
options.devtool = value;
});
Expand Down
7 changes: 7 additions & 0 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ function processOptions(options) {
var lastHash = null;
var compiler = webpack(options);

if(argv.progress) {
var ProgressPlugin = require("../lib/ProgressPlugin");
compiler.apply(new ProgressPlugin({
profile: argv.profile
}));
}

function compilerCallback(err, stats) {
if(!options.watch) {
// Do not keep cache anymore
Expand Down
18 changes: 12 additions & 6 deletions lib/ProgressPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
MIT License http:https://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
function ProgressPlugin(handler) {
this.handler = handler;
function ProgressPlugin(options) {
if(typeof options === "function") {
options = {
handler: options
};
}
options = options || {};
this.profile = options.profile;
this.handler = options.handler;
}
module.exports = ProgressPlugin;

ProgressPlugin.prototype.apply = function(compiler) {
var handler = this.handler || defaultHandler;
var profile = this.profile;
if(compiler.compilers) {
var states = new Array(compiler.compilers.length);
compiler.compilers.forEach(function(compiler, idx) {
Expand All @@ -18,9 +26,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
return state && state[0] || 0;
}).reduce(function(a, b) {
return a + b;
}) / states.length, states.map(function(state) {
return state && state[1];
}).filter(Boolean).join(" | ")]
}) / states.length, "[" + idx + "] " + msg]
.concat(Array.prototype.slice.call(arguments, 2)));
}));
});
Expand Down Expand Up @@ -146,7 +152,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
msg += " " + detail
});
}
if(compiler.options.profile) {
if(profile) {
state = state.replace(/^\d+\/\d+\s+/, "");
if(percentage === 0) {
lastState = null;
Expand Down

0 comments on commit 46b12b2

Please sign in to comment.