Skip to content

Commit

Permalink
fix: avoid unnecessary stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 11, 2020
1 parent d32aeda commit eedce42
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/webpack-cli/lib/utils/Compiler.js
Expand Up @@ -78,25 +78,29 @@ class Compiler {
process.exitCode = 1;
}
if (outputOptions.json === true) {
process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + '\n');
process.stdout.write(stats.toJson(outputOptions) + '\n');
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;

if (stats.compilation && stats.compilation.errors.length !== 0) {
const errors = stats.compilation.errors;
errors.forEach((statErr) => {
const errLoc = statErr.module ? statErr.module.resource : null;
statsErrors.push({ name: statErr.message, loc: errLoc });
});
}
const JSONStats = JSON.stringify(stats.toJson(outputOptions), null, 2);

if (typeof outputOptions.json === 'string') {
const JSONStats = stats.toJson(outputOptions);

try {
writeFileSync(outputOptions.json, JSONStats);
logger.success(`stats are successfully stored as json to ${outputOptions.json}`);
} catch (err) {
logger.error(err);
}
}

return this.generateOutput(outputOptions, stats, statsErrors);
}
}
Expand Down

0 comments on commit eedce42

Please sign in to comment.