score:1
steps:
- install webpack-bundle-analyzer and config that in your webpack config.
- try to use the webpack code splitting feature to reduce the file sizes at the first load time.
score:3
you don't need to eject. try this:
➜ simple-react-router git:(master) ✗ npm install webpack-bundle-analyzer --save-dev
- create a new file, i called mine: sample.js
➜ simple-react-router git:(master) ✗ cat sample.js
process.env.node_env = "production"
var bundleanalyzerplugin = require("webpack-bundle-analyzer")
.bundleanalyzerplugin
const webpackconfigprod = require("react-scripts/config/webpack.config.prod")
webpackconfigprod.plugins.push(
new bundleanalyzerplugin({
analyzermode: "static",
reportfilename: "report.html",
})
)
require("react-scripts/scripts/build")
- run with node
➜ simple-react-router git:(master) ✗ node sample.js
browserslist: caniuse-lite is outdated. please run next command `npm update caniuse-lite browserslist`
creating an optimized production build...
webpack bundle analyzer saved report to /users/dixitk13/code/simple-react-router/build/report.html
compiled successfully.
file sizes after gzip:
54.49 kb build/static/js/1.0ee1e308.chunk.js
1.9 kb build/static/js/main.73bea786.chunk.js
763 b build/static/js/runtime~main.229c360f.js
.
.
.
a new browser tab should open for you.
score:11
as per the official create react app documentation (https://create-react-app.dev/docs/analyzing-the-bundle-size/):
below are the steps:
step 1: add source map explorer
npm install --save source-map-explorer
alternatively, you may use yarn:
yarn add source-map-explorer
step 2: include npm script
"scripts": {
+ "analyze": "source-map-explorer 'build/static/js/*.js'",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
step 3: run the scripts to build the app
npm run build
step 4: run the scripts to analyze the build created in step3
npm run analyze
now you should see a screen in your browser opened like this
Source: stackoverflow.com
Related Query
- How to analyze create react app build size and reduce it?
- How to reduce react app build time and understanding behaviour of webpack when bundling
- How to determine the order of css in my create react app build with webpack and customize-cra?
- I create a build of my react app and connected with electron.js. now how to connect my backend from server folder with electron
- How to inject port and host using ENV variable in Create React App Proxy settings?
- How to read console.log from a mounted component with Enzyme and Jest in Create React App
- How to avoid very long paths and use absolute paths within a Create React App project?
- How to build react app using Dockerfile.dev and Yarn
- How to create and deploy a React App properly?
- How can I build a React app with Webpack and import an assets folder?
- How to deploy React app with docker and serve -s build
- Problem with npm build and babel in React Create App
- Create React App Build and Docker-Compose do not pass env variables
- How to reduce bundle size of the webpack build for a react application?
- How to reduce heroku slug size in react app
- React SSR(Server Side Rendering) for SEO before login and after login Create React App (CRA). How to do this in one project folder?
- How to: randomize element positions and size within a css "grid" in a React app
- How can I reduce the bundle size in React App when only using Authenticator from Amplify UI?
- How to exernalize @emotion/react, and @emotion/styled for Create React App
- How to compress build files in create react app without ejecting?
- How to create a json file and then return it in a get request back to react app
- How to create a React app directly in the current folder
- What is the difference between NextJs and Create React App
- How to create multiple page app using react
- React Native 0.64 won't build iOS app after updating Xcode to 12.5 and iOS to 14.5
- How to create forms with React and Rails?
- How to create and run a development build of an application using create-react-app configuration
- How to not show warnings in Create React App
- How to show build datetime on my react web app using create-react-app?
- How to include custom JS files in to React create app
More Query from same tag
- How to map data that we get from database to UI?
- Reach Router: Redirect to urI on function click
- How to position the react flatpickr inside a container instead of body
- Intercept event outside of Reactjs with native javascript
- Navigating from React to a non React web page on the same domain
- React-router not rendering page
- Simple React Routes not showing up
- react fetch post takes too long
- Storybook add on for setting server urls
- Removing object element from array of object in state (React.js)
- React Apollo: Dynamically update GraphQL query from Component state
- JavaScript Object is not assigned properly
- Disable account chooser FirebaseUI React
- String interpolation is not allowed in graphql tag. (Gatsby)
- How can I load data to react-stockcharts?
- Deck.gl: Listen for click on basemap
- React reducer works, but once going through the web-page becomes undefined
- Service Worker skipWaiting unable to activate currently waiting SW
- useEffect with function that update the state as dependency leads to infinite loop
- How to solve this error: 'Firebase' is not defined
- Get first data in JSON API
- React - Error: Maximum update depth exceeded - useReducer
- Node.js effects in Thermite for Electron
- refreshing / maunally typing url gives blank page - React router dom 6
- How to forcefully logout or delete token from localstorage after a refresh in react app?
- Error: Request failed with status code 403 - Problem with Axios, possible exchange for fetch
- How to assign multiple css classes as an array to a jsx variable in React, and then assign the variable to the className with join() function
- react-dom.development.js:55 Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys
- Any way to make "const {user, userId} = this.state" work if user references username and userId references id
- Close popup on form submit and display success/error message on parent component in reactjs