Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/react-dev-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ measureFileSizesBeforeBuild(buildFolder).then(previousFileSizes => {
});
```

#### `formatWebpackMessages({errors: Array<string>, warnings: Array<string>}): {errors: Array<string>, warnings: Array<string>}`
#### `formatWebpackMessages({errors: Array<string>, warnings: Array<string>, children}): {errors: Array<string>, warnings: Array<string>}`

Extracts and prettifies warning and error messages from webpack [stats](https://github.com/webpack/docs/wiki/node.js-api#stats) object.

Expand All @@ -236,7 +236,12 @@ compiler.hooks.invalid.tap('invalid', function() {
});

compiler.hooks.done.tap('done', function(stats) {
var rawMessages = stats.toJson({}, true);
var rawMessages = stats.toJson({
all: false,
children: true,
warnings: true,
errors: true,
});
var messages = formatWebpackMessages(rawMessages);
if (!messages.errors.length && !messages.warnings.length) {
console.log('Compiled successfully!');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-utils/WebpackDevServerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function createCompiler(webpack, config, appName, urls, useYarn) {
// We only construct the warnings and errors for speed:
// https://github.com/facebook/create-react-app/issues/4492#issuecomment-421959548
const messages = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true })
stats.toJson({ all: false, children: true, warnings: true, errors: true })
);
const isSuccessful = !messages.errors.length && !messages.warnings.length;
if (isSuccessful) {
Expand Down
17 changes: 15 additions & 2 deletions packages/react-dev-utils/formatWebpackMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,24 @@ function formatMessage(message, isError) {
return message.trim();
}

function recursivelyFindMessages(json, property) {
let messages = json[property];
if (json.children) {
json.children.forEach(function(child) {
const childMessages = recursivelyFindMessages(child, property);
messages = messages.concat(childMessages);
});
}
return messages;
}

function formatWebpackMessages(json) {
const formattedErrors = json.errors.map(function(message) {
const errors = recursivelyFindMessages(json, 'errors');
const formattedErrors = errors.map(function(message) {
return formatMessage(message, true);
});
const formattedWarnings = json.warnings.map(function(message) {
const warnings = recursivelyFindMessages(json, 'warnings');
const formattedWarnings = warnings.map(function(message) {
return formatMessage(message, false);
});
const result = { errors: formattedErrors, warnings: formattedWarnings };
Expand Down
7 changes: 6 additions & 1 deletion packages/react-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ function build(previousFileSizes) {
});
} else {
messages = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true })
stats.toJson({
all: false,
children: true,
warnings: true,
errors: true,
})
);
}
if (messages.errors.length) {
Expand Down