forked from webpack/webpack-cli
/
stats-options.js
26 lines (21 loc) · 906 Bytes
/
stats-options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const packageExists = require('./package-exists');
const webpack = packageExists('webpack') ? require('webpack') : undefined;
const { options: coloretteOptions } = require('colorette');
const getStatsOptions = (compiler) => {
let options = compiler.options
? typeof compiler.options.stats === 'object'
? Object.assign({}, compiler.options.stats)
: compiler.options.stats
: undefined;
// TODO remove after drop webpack@4
if (webpack.Stats && webpack.Stats.presetToOptions) {
if (!options) {
options = {};
} else if (typeof options === 'boolean' || typeof options === 'string') {
options = webpack.Stats.presetToOptions(options);
}
}
options.colors = typeof options.colors !== 'undefined' ? options.colors : coloretteOptions.enabled;
return options;
};
module.exports = { getStatsOptions };