Created by: joshwcomeau
Associated issue: #1858 (closed)
To analyze Webpack bundles, a "stats" JSON is required.
This PR allows that file to be created and saved to the build
directory, so that users can use it with Webpack-specific insight
tools like webpack-bundle-analyzer
without ejecting their
application.
Updated the README to include details for how to do this.
Test plan
1. check that the stats flag works
I ran yarn build --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 works in a created project
I ran yarn create-react-app test
to generate a new app.
After cd
-ing into the directory and installing its dependencies, I followed the steps I added to the the README for using webpack-bundle-analyzer
. Specifically I ran:
$ npm install --save webpack-bundle-analyzer
Then, I opened the project's package.json
and added a script:
"analyze": "npm run build -- --stats && webpack-bundle-analyzer build/bundle-stats.json",
Finally, I ran the new script:
$ npm run analyze
The project built, and a new browser window automatically opened, with the bundle stats: