From dbbdd70d63f07cb4b0e62dac0a1fd4ec0fc34b4d Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:48:27 -0600 Subject: [PATCH] fix: analyze script doesn't persist stats.json (#2290) --- config-overrides.js | 18 +++++++++++++----- package.json | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config-overrides.js b/config-overrides.js index 64ee4b9d1..1bda5bb80 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -90,14 +90,22 @@ function webpackOverride (config) { new webpack.ProvidePlugin({ process: 'process/browser', Buffer: ['buffer', 'Buffer'] - }), - new BundleAnalyzerPlugin({ - generateStatsFile: true, - analyzerMode: 'disabled', - openAnalyzer: false }) ]) + /** + * NODE_ENV is overridden by react-scripts/react-app-rewired-esm, + * so we set BUILD_ENV in the analyze script + */ + if (process.env.BUILD_ENV === 'analyze') { + config.plugins.push( + new BundleAnalyzerPlugin({ + analyzerMode: 'server', + openAnalyzer: true + }) + ) + } + config.module.rules = modifyBabelLoaderRuleForBuild(config.module.rules) config.module.rules.push({ test: /\.jsx?$/, diff --git a/package.json b/package.json index 1972f940b..6a721e48b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "test:e2e": "cross-env REACT_APP_ENV=test npx playwright test -c ./test/e2e", "test:build": "cross-env REACT_APP_ENV=test run-s build", "test:coverage": "jest --coverage", - "analyze": "webpack-bundle-analyzer build/stats.json", + "analyze": "cross-env BUILD_ENV=analyze npm run build", "eject": "react-scripts eject", "storybook": "start-storybook -p 9009", "build-storybook": "build-storybook --modern",