Skip to content

Commit 5d44850

Browse files
author
Colin Galindo
committed
Add instructions to use source-map-explorer
1 parent 2288ddf commit 5d44850

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ The [User Guide](https://github.com/facebookincubator/create-react-app/blob/mast
129129
- [Running Tests](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests)
130130
- [Developing Components in Isolation](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#developing-components-in-isolation)
131131
- [Making a Progressive Web App](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#making-a-progressive-web-app)
132+
- [Analyzing the Bundle Size](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#analyzing-the-bundle-size)
132133
- [Deployment](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment)
133134
- [Advanced Configuration](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration)
134135
- [Troubleshooting](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#troubleshooting)

packages/react-scripts/template/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
6161
- [Editor Integration](#editor-integration)
6262
- [Developing Components in Isolation](#developing-components-in-isolation)
6363
- [Making a Progressive Web App](#making-a-progressive-web-app)
64+
- [Analyzing the Bundle Size](#analyzing-the-bundle-size)
6465
- [Deployment](#deployment)
6566
- [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
6667
- [Building for Relative Paths](#building-for-relative-paths)
@@ -1206,6 +1207,37 @@ Learn more about React Storybook:
12061207

12071208
You can turn your React app into a [Progressive Web App](https://developers.google.com/web/progressive-web-apps/) by following the steps in [this repository](https://github.com/jeffposnick/create-react-pwa).
12081209

1210+
## Analyzing the Bundle Size
1211+
1212+
[Source map explorer](https://www.npmjs.com/package/source-map-explorer) analyzes
1213+
JavaScript bundles using the source maps. This helps you understand where code
1214+
bloat is coming from.
1215+
1216+
To add Source map explorer to a Create React App project, follow these steps:
1217+
1218+
```
1219+
npm install source-map-explorer --save-dev
1220+
```
1221+
1222+
Then in `package.json`, add the following line to `scripts`
1223+
On Windows you will have to type the full file path out.
1224+
1225+
```diff
1226+
"scripts": {
1227+
"start": "react-scripts start",
1228+
"build": "react-scripts build",
1229+
"test": "react-scripts test --env=jsdom",
1230+
+ "analyze": "source-map-explorer build/static/js/main.* "
1231+
```
1232+
1233+
Then to analyze the bundle run the production build then run the analyze
1234+
script.
1235+
1236+
```
1237+
npm run build
1238+
npm run analyze
1239+
```
1240+
12091241
## Deployment
12101242

12111243
`npm run build` creates a `build` directory with a production build of your app. Set up your favourite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main.<hash>.js` are served with the contents of the `/static/js/main.<hash>.js` file. For example, Python contains a built-in HTTP server that can serve static files:

0 commit comments

Comments
 (0)