Skip to content

Commit

Permalink
Optimize webpack rebuild speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Sep 22, 2018
1 parent 2150693 commit 84de53e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/react-dev-utils/FileSizeReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function printFileSizesAfterBuild(
var assets = (webpackStats.stats || [webpackStats])
.map(stats =>
stats
.toJson()
.toJson({ all: false, assets: true })
.assets.filter(asset => /\.(js|css)$/.test(asset.name))
.map(asset => {
var fileContents = fs.readFileSync(path.join(root, asset.name));
Expand Down
6 changes: 5 additions & 1 deletion packages/react-dev-utils/WebpackDevServerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ function createCompiler(webpack, config, appName, urls, useYarn) {
// We have switched off the default Webpack output in WebpackDevServer
// options so we are going to "massage" the warnings and errors and present
// them in a readable focused way.
const messages = formatWebpackMessages(stats.toJson({}, true));
// 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 })
);
const isSuccessful = !messages.errors.length && !messages.warnings.length;
if (isSuccessful) {
console.log(chalk.green('Compiled successfully!'));
Expand Down
4 changes: 3 additions & 1 deletion packages/react-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ function build(previousFileSizes) {
if (err) {
return reject(err);
}
const messages = formatWebpackMessages(stats.toJson({}, true));
const messages = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true })
);
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
Expand Down

0 comments on commit 84de53e

Please sign in to comment.