How to analyze the bundle size in React App
In this tutorial, we are going to learn about how to analyze the create react app bundle size using source-map-explorer.
Analyzing the bundle size
- First, we need to install a package called source-map-explorer in create react app using npm.
npm i source-map-explorer
Source map explorer helps us to analyze the JavaScript bundles using source maps.
- Now, open your
package.json
file and add the following line toscripts
object.
"analyze": "source-map-explorer 'build/static/js/*.js'",
- Analyze the bundle size by running the following commands.
npm run build
npm run analyze
npm run build
is used to build your react app code to production.
npm run analyze
is used to analyze the code.