From df1b6142322f8874739f37eedc0de0baaf68e8de Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Tue, 20 Jun 2017 10:05:01 +0100 Subject: [PATCH] Add a compile time to webpack dev server and react-scripts --- packages/react-dev-utils/WebpackDevServerUtils.js | 8 +++++--- packages/react-scripts/scripts/build.js | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 648fef3e1fb..6be5bbff502 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -143,6 +143,8 @@ function createCompiler(webpack, config, appName, urls, useYarn) { // "done" event fires when Webpack has finished recompiling the bundle. // Whether or not you have warnings or errors, you will get this event. compiler.plugin('done', stats => { + const compileTime = parseFloat((Math.abs(stats.endTime - stats.startTime) / 1000).toFixed(2)); + if (isInteractive) { clearConsole(); } @@ -153,7 +155,7 @@ function createCompiler(webpack, config, appName, urls, useYarn) { const messages = formatWebpackMessages(stats.toJson({}, true)); const isSuccessful = !messages.errors.length && !messages.warnings.length; if (isSuccessful) { - console.log(chalk.green('Compiled successfully!')); + console.log(chalk.green('Compiled successfully in ' + compileTime + 's!')); } if (isSuccessful && (isInteractive || isFirstCompile)) { printInstructions(appName, urls, useYarn); @@ -162,14 +164,14 @@ function createCompiler(webpack, config, appName, urls, useYarn) { // If errors exist, only show errors. if (messages.errors.length) { - console.log(chalk.red('Failed to compile.\n')); + console.log(chalk.red('Failed to compile after ' + compileTime + 's.\n')); console.log(messages.errors.join('\n\n')); return; } // Show warnings if no errors were found. if (messages.warnings.length) { - console.log(chalk.yellow('Compiled with warnings.\n')); + console.log(chalk.yellow('Compiled in ' + compileTime + 's with warnings.\n')); console.log(messages.warnings.join('\n\n')); // Teach some ESLint tricks. diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 2e4bc21ee5b..045951dfd6b 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -58,8 +58,10 @@ measureFileSizesBeforeBuild(paths.appBuild) }) .then( ({ stats, previousFileSizes, warnings }) => { + const compileTime = parseFloat((Math.abs(stats.endTime - stats.startTime) / 1000).toFixed(2)); + if (warnings.length) { - console.log(chalk.yellow('Compiled with warnings.\n')); + console.log(chalk.yellow('Compiled in ' + compileTime + 's with warnings.\n')); console.log(warnings.join('\n\n')); console.log( '\nSearch for the ' + @@ -72,7 +74,7 @@ measureFileSizesBeforeBuild(paths.appBuild) ' to the line before.\n' ); } else { - console.log(chalk.green('Compiled successfully.\n')); + console.log(chalk.green('Compiled successfully in ' + compileTime + 's!')); } console.log('File sizes after gzip:\n');