From 7dd54a2da56ac46a1764b277339a2195b437a32f Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Sun, 5 Apr 2020 13:19:13 -0700 Subject: [PATCH] Add back in --stats output from webpack. This commit is a manual revert of the following commits: https://github.com/facebook/create-react-app/commit/e7a427ad161b7b58868409d99307d8b68fad1335 https://github.com/facebook/create-react-app/commit/140e182e7d7fbeb8d507b6be4813a4ce0bf9b6d8 And a re-introduction of https://github.com/facebook/create-react-app/commit/7c8593845830c585a780f4e40268e7b4f442c7a4 Fixes: https://github.com/facebook/create-react-app/issues/8789 Fixes: https://github.com/facebook/create-react-app/issues/6904 Tested: Manually ran yarn link and then ran yarn build from a 3.x version of CRA with react-scripts linked in from this patch. Verification: Saw that a bundle-stats.json file was written out where as before in the pre-linked version it was not. --- packages/react-scripts/package.json | 1 + packages/react-scripts/scripts/build.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 63e7faf390c..4f6ee11625b 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -37,6 +37,7 @@ "babel-loader": "8.1.0", "babel-plugin-named-asset-import": "^0.3.6", "babel-preset-react-app": "^9.1.2", + "bfj": "^7.0.2", "camelcase": "^5.3.1", "case-sensitive-paths-webpack-plugin": "2.3.0", "css-loader": "3.4.2", diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index fa30fb09a3f..b51df86101b 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -34,6 +34,7 @@ verifyTypeScriptSetup(); const path = require('path'); const chalk = require('react-dev-utils/chalk'); const fs = require('fs-extra'); +const bfj = require('bfj'); const webpack = require('webpack'); const configFactory = require('../config/webpack.config'); const paths = require('../config/paths'); @@ -59,6 +60,9 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { process.exit(1); } +const argv = process.argv.slice(2); +const writeStatsJson = argv.indexOf('--stats') !== -1; + // Generate configuration const config = configFactory('production'); @@ -210,11 +214,20 @@ function build(previousFileSizes) { return reject(new Error(messages.warnings.join('\n\n'))); } - return resolve({ + const resolveArgs = { stats, previousFileSizes, warnings: messages.warnings, - }); + }; + + if (writeStatsJson) { + return bfj + .write(paths.appBuild + '/bundle-stats.json', stats.toJson()) + .then(() => resolve(resolveArgs)) + .catch(error => reject(new Error(error))); + } + + return resolve(resolveArgs); }); }); }