Reputation: 13336
I read various answers like this regarding reducing the bundle size. First I wanted to understand what is going on with my 13MB bundle, so I've installed the Webpack Bundle Size Analyzer. It generated this output:
There are a few things I don't understand:
Update: Found the answer for #1. React-color requires ReactCSS which requires a different version of react and lodash. Without React-color my bundle dropped from 13MB to 8MB. I will try to find a way to re-use react and lodash.
Upvotes: 1
Views: 763
Reputation: 7026
It seems that you have eval-source-map
devtool option in your webpack config file, that's why you are getting such huge bundle size. This way, sourcemaps are putting inside of bundle js file.
Try to change this option to source-map
to build source maps separately.
// webpack.config.js
{
devtool: 'source-map',
// ... other options
}
Upvotes: 3
Reputation: 8503
1) Sometimes other dependencies require again lodash and / or react, so these dependencies are pulled in multiple times by webpack (usually happens when the version differs), here the DedupePlugin
should help. The final bundle size also depends on your devtool
entry in webpack, so in development it is usually much bigger as you probably have sourcemaps enabled and a your build is not optimized. Hard to tell without your actual webpack config.
2) Maybe webpack is already deduping?
3) last line says 400KB
4) You can definitely save a few kbs. A good way to start is using lodash-webpack-plugin
with babel-plugin-lodash
, this will import only the lodash methods you are actually using instead of the complete library. You can also just require the bits you need from material-ui
as outlined in this answer.
I recently added the webpack-dashboard
to my webpack config, so I instantly see the output and percentages that make up my bundle size, so maybe you think twice about adding huge dependencies if you don't really need them.
Upvotes: 2