react-dom blowing out webpack bundle size MASSIVELY
Solution 1
http://elijahmanor.com/react-file-size/
In v15.4.0 the file size of react-dom grew from 1.17kB to 619.05kB. Which means my webpack setup isn't doing anything wrong bundling files. The reason why this module grew so large is because code was transferred from the react module.
Solution 2
If you look into the corresponding folders under the node_modules
folder, and note the file sizes, you'll see that there's nothing to be surprised about:
That is, the size of the bundle grows noticeably because the size of react-dom.js is large.
Solution 3
I had to change my webpack.config.js, from
devtool: 'inline-source-map'
to
devtool: 'source-map'
Now it generates a much smaller .js + a separate .js.map file, for each of the chunks.
Notice the JS size is even less than react-dom.production.min.js in node_modules:
Related videos on Youtube
Toby Flemming
Updated on June 04, 2022Comments
-
Toby Flemming almost 2 years
This has got to be one of the strangest issues with webpack i have ever come across...
Check out this bundle breakdown: react 116.01KB - fair enough
react-dom 533.24KB - seriously WTF
I thought it may be a corruption in my dependencies but nuking node_modules and reinstalling doesn't have any effect. I guess it's something to do with the way webpack is bundling it but i'm lost for ideas. The way i'm handing .js imports is pretty stock standard.
// webpack.config.js const path = require('path'); // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const ExtractTextPlugin = require('extract-text-webpack-plugin'); const Dashboard = require('webpack-dashboard'); const DashboardPlugin = require('webpack-dashboard/plugin'); const dashboard = new Dashboard(); module.exports = { context: path.join(__dirname, 'src'), entry: { bundle: './index.js', }, output: { filename: 'bundle.js', path: path.join(__dirname, 'build'), }, module: { rules: [ { test: /\.html$/, use: 'file-loader?name=[name].[ext]', }, { test: /.scss$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: [ 'css-loader', 'postcss-loader', ], }), }, { test: /\.js$/, exclude: /node_modules/, use: 'babel-loader', }, ], }, plugins: [ // new BundleAnalyzerPlugin(), new ExtractTextPlugin('styles.css'), new DashboardPlugin(dashboard.setData), ], devServer: { quiet: true, }, }; // .babelrc { "presets": [ "react", "es2015" ], "plugins": ["transform-object-rest-spread"] }
-
Toby Flemming about 7 yearsI'm aware that my bundle can be compressed down. My concern is the size of react-dom relative to react... I get a smaller bundle in production mode but react-dom is still not right.
-
Alessander França about 7 yearsI had a similar problem and solved with this plugins, in production react-dom becames 30k. To solve the 2mb compressed at my production bundle, I used route code splitting
-
Toby Flemming about 7 yearsI'm using Webpack 2. It does OccurrenceOrderPlugin and UglifyJsPlugin by default when you run
webpack -p
-
Alessander França about 7 yearsI am using Wepack 2 either. When I change -p for theses plugins my bundle reduced from 8mb to 2mb
-
Toby Flemming about 7 yearsThe plugins don't do anything for me... webpack.js.org/guides/migrating/…
-
Toby Flemming about 7 yearsI've got an old project that uses [email protected] and is 1KB... What has caused such a big jump?
-
Gajus about 7 yearsThe
[email protected]
was just linkingreact
package. -
vsync about 5 yearsTerser is superior to uglify. use
terser-webpack-plugin
-
Colin D almost 4 yearsThe values being listed are development bundle sizes. Generally a production or minimized build is shipped, probably gzip too, and so react.min.js.gz + react-dom.min.js.gz <50kb. Using "mode": "production" in the webpack build (now the default in webpack) will produce these expected smaller bundle sizes