question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Solution: webpack-bundle-analyzer without ejecting.

See original GitHub issue

Ejecting is a real shame for any instance of create-react-app, so I found a way to use webpack-bundle-analyzer without ejecting. Hopefully this will save someone out there from having to eject to make this addition.

  1. Create a file in root, I call mine “build.js”
  2. Add this javascript.
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")
  1. node build.js

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:96
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
cag2050commented, Jun 17, 2018

Add webpack-bundle-analyzer with ejecting, modify code in file: config/webpack.config.prod.js.

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
  plugins: [
    ...
    new BundleAnalyzerPlugin()
  ]
}

demo: https://github.com/cag2050/antd_mobx_demo/blob/master/config/webpack.config.prod.js

9reactions
freund17commented, Jan 14, 2019

For everyone coming here from google and using a recent version of react-scripts: https://github.com/facebook/create-react-app/pull/3945 landed, so now you can use

{
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build --stats && webpack-bundle-analyzer build/bundle-stats.json -m static -r build/bundle-stats.html -O",
    "test": "react-scripts test"
  }
}

to include bundle-stats.json and bundle-stats.html in your build-directory. (The latter is what you came here for.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack Bundle Analyzer with Create React App ... - YouTube
Webpack Bundle Analyzer with Create React App without ejecting. ; https://www.udemy.com/user/maksym-rud... Support this channel: Patreon - ; https ...
Read more >
You can use create-react-app with webpack-bundle ...
You can use create-react-app with webpack-bundle-analyzer without ejecting: npm run build -- --stats.
Read more >
[Without Ejecting] Analyze Create React App Bundle Size
[Without Ejecting] Analyze Create React App Bundle Size ... The webpack-bundle-analyzer is a great package to analyze the bundle size of ReactJS app....
Read more >
Analyze your Create React App bundle size - without ejecting
Step 1 - Dependencies​​ The plugin we'll use to analyze bundle size is webpack-bundle-analyzer. To avoid ejecting we'll be using CRACO (Create ...
Read more >
How to configure webpack-bundle-analyzer for react?
4 Answers 4 · Add some dependencies by executing npm install --save-dev progress-bar-webpack-plugin webpack-bundle-analyzer · Create a new folder ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found