Created by: joshwcomeau
As discussed in #1858 (closed), we want to generate a JSON stats object from Webpack, so that folks can use popular tools like webpack-bundle-analyzer
without ejecting.
This change adds a new script: build:with-stats
. This new script does exactly the same thing as build
, but with the added work of generating build/bundle-stats.json
, using bfj to create a write stream.
Test plan:
1. check that the build script works
I ran yarn build:with-stats
in the root directory of the project. Once it completed, I verified that build/bundle-stats.json
existed. I dragged it into Webpack Visualizer to check that the file is correct
2. check that it creates the new script
I ran yarn create-react-app test
to generate a new app. I checked that the new script is documented in that initial echo:
I ran cd test
, and then yarn build:with-stats
. Similarly, I verified that the file was created in build/bundle-stats.json
.
3. check the instructions for webpack-bundle-analyzer
In the new README, I added steps for using with webpack-bundle-analyzer
. I verified that they work by:
- running
yarn add webpack-bundle-analyzer
- copying this line to package.json:
"analyze": "npm run build:with-stats && webpack-bundle-analyzer build/bundle-stats.json",
- running
yarn analyze
After building, it automatically opened a browser window: