Skip to content

Commit a4106ea

Browse files
committed
fix(stats): allow stats to respect config for MultiCompiler, MultiStats
1 parent 27e604e commit a4106ea

File tree

9 files changed

+44
-14
lines changed

9 files changed

+44
-14
lines changed

bin/webpack.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ function ifArg(name, fn, init) {
150150
}
151151
}
152152

153+
function hasPresetPredicate(options) {
154+
return typeof options.stats === "boolean" || typeof options.stats === "string";
155+
}
156+
157+
function hasPreset(optionsArray) {
158+
options = Array.isArray(optionsArray) ? optionsArray : [optionsArray];
159+
return options.some(hasPresetPredicate);
160+
}
161+
153162
function processOptions(options) {
154163
// process Promise
155164
if(typeof options.then === "function") {
@@ -160,11 +169,20 @@ function processOptions(options) {
160169
return;
161170
}
162171

172+
// var firstOptions = Array.isArray(options) ? (options[0] || {}) : options;
163173
var firstOptions = Array.isArray(options) ? (options[0] || {}) : options;
164-
165-
if(typeof options.stats === "boolean" || typeof options.stats === "string") {
174+
if(hasPreset(options)) {
166175
var statsPresetToOptions = require("../lib/Stats.js").presetToOptions;
167-
options.stats = statsPresetToOptions(options.stats);
176+
177+
if(Array.isArray(options)) {
178+
179+
options = options.map(function(singleOption) {
180+
singleOption.stats = statsPresetToOptions(singleOption.stats);
181+
return singleOption;
182+
})
183+
} else {
184+
options.stats = statsPresetToOptions(options.stats);
185+
}
168186
}
169187

170188
var outputOptions = Object.create(options.stats || firstOptions.stats || {});

lib/Stats.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ Stats.presetToOptions = function(name) {
793793
var pn = (typeof name === "string") && name.toLowerCase() || name;
794794
if(pn === "none" || !pn) {
795795
return {
796+
performance: false,
796797
hash: false,
797798
version: false,
798799
timings: false,
@@ -813,6 +814,7 @@ Stats.presetToOptions = function(name) {
813814
} else {
814815
return {
815816
hash: pn !== "errors-only" && pn !== "minimal",
817+
performance: true,
816818
version: pn === "verbose",
817819
timings: pn !== "errors-only" && pn !== "minimal",
818820
assets: pn === "verbose",

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
66
"dependencies": {
7-
"acorn": "^4.0.3",
7+
"acorn": "^4.0.4",
88
"acorn-dynamic-import": "^2.0.0",
99
"ajv": "^4.7.0",
1010
"ajv-keywords": "^1.1.1",
@@ -14,7 +14,7 @@
1414
"json-loader": "^0.5.4",
1515
"loader-runner": "^2.2.0",
1616
"loader-utils": "^0.2.16",
17-
"memory-fs": "~0.3.0",
17+
"memory-fs": "^0.4.1",
1818
"mkdirp": "~0.5.0",
1919
"node-libs-browser": "^2.0.0",
2020
"object-assign": "^4.0.1",
@@ -48,19 +48,19 @@
4848
"js-beautify": "^1.5.10",
4949
"less": "^2.5.1",
5050
"less-loader": "^2.0.0",
51-
"mocha": "^3.1.0",
51+
"mocha": "^3.2.0",
5252
"mocha-lcov-reporter": "^1.0.0",
5353
"nsp": "^2.6.1",
5454
"raw-loader": "~0.5.0",
5555
"react": "^15.2.1",
5656
"react-dom": "^15.2.1",
5757
"script-loader": "~0.7.0",
58-
"should": "^11.1.1",
58+
"should": "^11.1.2",
5959
"style-loader": "~0.13.0",
6060
"url-loader": "~0.5.0",
6161
"val-loader": "~0.5.0",
6262
"vm-browserify": "~0.0.0",
63-
"webpack-dev-middleware": "^1.0.0",
63+
"webpack-dev-middleware": "^1.9.0",
6464
"worker-loader": "~0.7.0"
6565
},
6666
"engines": {

test/Stats.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe("Stats", function() {
4747
c.apply(new webpack.optimize.OccurrenceOrderPlugin());
4848
});
4949
c.run(function(err, stats) {
50+
options = Array.isArray(options) ? options[0] : options;
5051
if(err) return done(err);
5152

5253
if(/error$/.test(testName)) {
@@ -59,7 +60,6 @@ describe("Stats", function() {
5960
colors: false
6061
};
6162
var hasColorSetting = false;
62-
6363
if(typeof options.stats !== "undefined") {
6464
toStringOptions = options.stats;
6565

@@ -165,7 +165,8 @@ describe("Stats", function() {
165165
reasons: false,
166166
usedExports: false,
167167
providedExports: false,
168-
colors: true
168+
colors: true,
169+
performance: true
169170
});
170171
});
171172
it("truthy values behave as 'normal'", function() {
@@ -194,7 +195,8 @@ describe("Stats", function() {
194195
errors: false,
195196
errorDetails: false,
196197
warnings: false,
197-
publicPath: false
198+
publicPath: false,
199+
performance: false
198200
});
199201
});
200202
it("falsy values behave as 'none'", function() {

test/statsCases/define-plugin/webpack.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var webpack = require("../../../");
22
module.exports = [
33
{
44
entry: "./index",
5-
stats: "errors-only",
65
plugins: [
76
new webpack.DefinePlugin({
87
VALUE: "123"
@@ -11,7 +10,6 @@ module.exports = [
1110
},
1211
{
1312
entry: "./index",
14-
stats: "errors-only",
1513
plugins: [
1614
new webpack.DefinePlugin({
1715
VALUE: "321"

test/statsCases/preset-none-array/expected.txt

Whitespace-only changes.

test/statsCases/preset-none-array/index.js

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = [
2+
{
3+
entry: "./index",
4+
stats: "none"
5+
},
6+
{
7+
entry: "./index",
8+
stats: "none"
9+
}
10+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
entry: "./index",
33
stats: false
4-
};
4+
};

0 commit comments

Comments
 (0)